homepage Welcome to WebmasterWorld Guest from 54.242.241.20
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewrite Question
301 to a new URL handling query strings
SEOMike

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4265267 posted 6:18 pm on Feb 10, 2011 (gmt 0)

A client is changing URLs and redesigning their site. Their current site has awful query strings which dynamically build every page. (ie. index.php?option=com_content&task=view&id=XX&Itemid=YY) Redirecting these pages will be a pain, but I can handle that.

My real question is how do I redirect index.php (the main page of the site with inbound links) to index.htm while ignoring index.php with a query string attached? My limited understanding of this has me thinking that anytime the redirect sees index.php in any form (with or without the query string) it'll redirect to index.php's target (the new homepage).

I'm worried it'll work like this:

301 redirect index.php -> index.htm

301 redirect index.php?awful_QS -> index.htm


I need it to work like this:

301 redirect index.php -> index.htm

301 redirect index.php?awful_QS -> matching_new_page.htm

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4265267 posted 6:56 pm on Feb 10, 2011 (gmt 0)

This code will trigger for a blank query string:

RewriteCond %{QUERY_STRING} !.

and goes before the
RewriteRule that performs the redirect.

However, I would caution against redirecting to a named index page.

You should instead redirect to
www.example.com/ with a trailing slash. Your redirect should look something like this:

RewriteRule ^index\.(php|html?) http://www.example.com/ [R=301,L]

Use this code to serve the index.html file when the "/" URL is requested:

DirectoryIndex index.htm
SEOMike

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4265267 posted 9:01 pm on Feb 10, 2011 (gmt 0)

Great. Thanks!

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