Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess 301 redirect dynamic URL to static

losing the query string, but not rewriting



9:56 am on Sep 4, 2007 (gmt 0)

10+ Year Member

I want to redirect a set of old dynamic URLs to separate set of static URLs and need to lose the query strings


old: index.php?q=123 to new: /abcd/
old: index.php?q=124 to new: /efgz/


I've tried the following but its retaining the query string:

RewriteCond %{query_STRING} ^q=123$
RewriteRule ^index\.php$ /abcd/ [R=301,L]

Is there a way to do this purely with htaccess?


10:38 am on Sep 4, 2007 (gmt 0)

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

I think that

RewriteRule ^index\.php$ /abcd/? [R=301,L]

will lose the query string in the redirect.

Additionally, you should add the domain to the redirect so that you don't allow indexing at both www and non-www. You might have a separate rule for that already, but if you fail to add the domain here as well, then some requests will see a double redirect - and that is bad.

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

Finally, the root page of the site is the most important page of the site. It is very bad form to serve a redirect to a deep internal URL within the site.

Consider using a rewrite to pull content from a deep filepath while continuing to show the root URL. URLs and files are two different things.


Featured Threads

Hot Threads This Week

Hot Threads This Month