help requested with rewrite and redirect rules

Using mod_rewrite to handle various content issues

help requested with rewrite and redirect rules

Postby rsleventhal » Tue Jun 03, 2008 4:31 am

Hi all,

I've been using the suggestion sent to me via richardk on this board for rewriting some dynamic query string URLS to more SEO friendly ones and it's working great. My current .htaccess file has:
Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?$1 [QSA,L]

This correctly changes URLs like http://example.com/index.php?anypage to http://example.com/anypage.

I've found some stale links in some of the search engines, so now I need to add about 10 Redirect 301 rules. Problem is, they're getting caught in the rewrite ruleset. Example:

http://example.com/contactus.html no longer exists. I would like that URL to be directed to http://example.com/contactus (really index.php?contactus) but no matter where I put the redirect 301 rule, I wind up with /contactus?contactus.html

Any pointers (including to relevant reading so I can figure this out) would be greatly appreciated.

Many thanks,
-Ray
rsleventhal
 
Posts: 15
Joined: Thu May 15, 2008 7:17 am

Postby richardk » Tue Jun 03, 2008 1:42 pm

What have you tried?

You might have missed the L flag or put the redirect rules at the end of the file. Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Redirects
RewriteRule ^contactus\.html$ /contactus [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rsleventhal » Wed Jun 04, 2008 4:09 am

Hi richard,

Yes, I did both; forgot the L flag and put the redirects at the end.

Thank you so much for your help...spot on, as usual.

Kind regards,
-Ray
rsleventhal
 
Posts: 15
Joined: Thu May 15, 2008 7:17 am


Return to Content

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron