Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess redirect singly url query strings

Best way to redirect individual, single source urls to specific target urls



7:38 am on Sep 24, 2013 (gmt 0)

10+ Year Member

Hi All,

I am new to this and am struggling past two days.

What I am trying to do is redirect
example.com/company/index.php to example.com/about_us

example.com/company/index.php?page=12 to example.com/about_us/history

example.com/info/index.php?page=12 to example.com/contact_us

I have tried the following test code:

RewriteEngine on
RewriteRule ^policies/$ http://www.example.com/news? [R=301,L]

(http://legacy_web/about_us/ to http://www.example.com/news)

RewriteCond %{QUERY_STRING} page=23$
RewriteRule (.*) http://www.example.com? [R=301,L]

(http://legacy_web/about_us/index.php?page=23 to http://www.example.com)

RewriteRule ^policies/index\.php$ http://www.example.com? [R=301,L]

(http://legacy_web/about_us/index.php to http://www.example.com)

These work. The only issue is that even http://legacy_web/info/index.php?page=23 redirects to www.example.com
similar to the policies above.

A shove in the right direction much appreciated.

Thank you for your time and help

[edited by: phranque at 9:31 am (utc) on Sep 24, 2013]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]


7:14 am on Oct 2, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

However, example.com/investors/index.php?page=22 is different from example.com/investors/index.php

Yes it is. However, example.com/investors/index.php?page=22 should be the same as example.com/investors/?page=22 with both including ?page=22

(2 places)

Other fixes:




!^www\.example\.com\.au [NC]


3:23 am on Oct 21, 2013 (gmt 0)

10+ Year Member


Apologies for resurrecting this thread.

These Redirect rules work well when I run them on my local development server.

However, when I run them on the production server they give a 404 error instead of triggering the redirects.

It took me a while to figure out that it could be due to the "proxy" server (web server sitting between the client and the actual CMS app server).

Seems like the proxy module gets hold of the URL first pushes it off the server which promptly sends back the wrong response i.e. 404.

I need the rewrite to occur first, then the new URL submitted and passed through to the proxy.

Then again I may be wrong.

In this scenario, should the rewrite rules still work irrespective of the "proxy"?


5:32 am on Oct 21, 2013 (gmt 0)

10+ Year Member

I forgot to add,

Does it matter if the target url is absolute or relative?
e.g. /aboutus/companyprofile/press? vs http://www.example.com.au/aboutus/companyprofile/press? [R=301,L]

Someone I spoke to suggested that if redirecting to the same domain, the target should be relative

If redirecting to a different domain, the target url should be absolute.

I gave this a go, however, this did not work either.


8:02 am on Oct 21, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

If you're redirecting rather than simply rewriting, always use a full URL including protocol.

The form with leading slash isn't strictly speaking a relative URL either-- those are the ones with leading directoryname or, in html, leading ../../ and worse. But a leading slash means "reattach whatever you used before" so it doesn't do anything about domain-name canonicalization (and potentially even http vs https if your site goes both ways).

However this should have no effect on whether your redirects work or not. And since you're redirecting rather than rewriting, you can easily see in the address bar where the browser "thinks" it is. Does it say what you expected it to say? If no, there's a problem with the rule. If yes, the problem is elsewhere.


11:16 pm on Oct 21, 2013 (gmt 0)

10+ Year Member

Thanks lucy24

Seems like there is a problem with the rule.
The address bar displays the original url and not the target url.

I am flummoxed.

The rules are exactly what I shared above.
These work on my local machine running XAMPP

Add them to the test server (tomcat) and it doesn't work.

Another issue that I see is the the address bar displays subdomain.domain.com.au//
An extra trailing slash at the end.


5:53 am on Oct 22, 2013 (gmt 0)

10+ Year Member

Issue resolved.

I added a leading slash in my rewrite rule e.g. a slash before policies

RewriteRule ^/policies/$ http://www.example.com/news? [R=301,L]

All the redirect rules work now.

Thank you very much :-)


5:20 pm on Oct 22, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Leading slash? In htaccess? In conjunction with the preceding post about a double slash, this sounds ominous-- as if something, somewhere is adding a slash after the domain-name slash.


10:37 pm on Oct 22, 2013 (gmt 0)

10+ Year Member

Well I don't know what was going on.

However, once I added the slash after the caret symbol all the redirects worked. It also resolved the issue where an extra slash was being added after subdomain.domain.com.au/

Surprisingly the rules worked on my local XAMPP setup without the slash after the caret symbol.

My guess is that the forward proxy on our test server is set up in a way that it required this slash to match the pattern.
This 38 message thread spans 2 pages: 38

Featured Threads

Hot Threads This Week

Hot Threads This Month