homepage Welcome to WebmasterWorld Guest from 54.211.157.103
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess 301 redirect dynamic URL to static
losing the query string, but not rewriting
Adam_C




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

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

e.g.

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

etc.

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?

 

g1smd




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved