Forum Moderators: phranque
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)shp/widgets/detail-nm/(.*)$ $1shp/widgets/detail-nm.php?product=$2
RewriteRule ^shp/gadgets/(.+)/?$ /shp/detail-gadgets.php?product=$1 [L]
(and a few more rewrite rules similar to the second one)
I need to add:
RewriteCond %{HTTP_HOST}!^www\.mydomain\.com
RewriteRule ^(.*)$ [mydomain.com...] [R=301,L]
Will the 'RewriteBase /' interfere with this? It looks to me like it would, but I don't understand this stuff that well. Which is why I didn't set up the redirects on all my sites yet - too scared of messing up something that isn't broken (yet anyway).
Your RewriteBase is the default, and I doubt that it would affect your external redirect.
However, the only way to know is to test it. Make a backup of your 'safe' .htaccess, and if this new code messes things up, you can simply rename the backup to .htaccess, and be back online in seconds.
Since you are using a negative match, you'll need to add a condition to suppress the redirect if the client does not provide a Host header. Otherwise, you'll put the client and your server into an 'infinite loop' for all HTTP/1.0 clients (which do not provide a Host header). The new line simply checks to make sure the HTTP_HOST variable contains at least one character (i.e. is non-blank).
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^(.*)shp/widgets/detail-nm/(.*)$ $1shp/widgets/detail-nm.php?product=$2
RewriteRule ^shp/gadgets/(.+)/?$ /shp/detail-gadgets.php?product=$1 [L]
(and a few more rewrite rules similar to the second one)
[edited by: jdMorgan at 12:38 am (utc) on May 25, 2005]
[edit reason] Examplified. [/edit]