Reputation: 5107
I have the following rule in my .htaccess file that should redirect a request like this:
http://www.olddomain.com/some/url/ -> http://www.newdomain.com/some/url/
unless the path matches something like /images/someimage.jpg
There's a few exceptions like this, built into the rule:
RewriteRule ^(?!images/.*|css/.*|js/.*) http://www.newdomain.com/$1 [R=301,L]
This is behaving as expected when I test using http://htaccess.madewithlove.be/
But, on the live server, $1 is never set. Urls that match the pattern are just redirected to the home page "/"
This is the very first rule of my htaccess file, after RewriteEngine On
Upvotes: 1
Views: 256
Reputation: 785196
Replace your rule with this:
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/((images|css|js)/ [NC]
RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [R=301,L]
Upvotes: 1