pingpongi
pingpongi

Reputation: 11

htaccess and WordPress problems

I wanna redirect all my wordpress pages from one domain to another, such as:

So I added to htaccess of domain1.com: RewriteRule (.*)$ http://www.domain2.com\/$1 [R=301,L]

But I want to make certain files exceptions to the above rule, so I also added:

RewriteCond %{REQUEST_URI} ^(images|javascripts|stylesheets|css|images-globa|js-global|js|htm|html).*

but the second rule doesn't seem to work. :(

Upvotes: 1

Views: 46

Answers (1)

Jon Lin
Jon Lin

Reputation: 143966

Those aren't exceptions, those are "the request MUST be images/javascripts/stylesheets/etc in order to redirect", so you've got it backwards. You want a ! in there:

RewriteCond %{REQUEST_URI} !(images|javascripts|stylesheets|css|images-globa|js-global|js|htm|html)
RewriteRule (.*)$ http://www.domain2.com\/$1 [R=301,L]

Though I'm assuming you're way overreaching with the regular expression there, some of those look like you are matching against only the extension, so:

RewriteCond %{REQUEST_URI} !(images|javascripts|stylesheets|css|images-globa|js-global)
RewriteCond %{REQUEST_URI} !\.(js|html?|png|je?pg|gif)$ [NC]
RewriteRule (.*)$ http://www.domain2.com\/$1 [R=301,L]

Upvotes: 1

Related Questions