homepage Welcome to WebmasterWorld Guest from 184.73.87.85
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
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




msg:4265269
 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




msg:4265305
 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




msg:4265366
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved