Reputation: 58
How can I .htaccess 301 redirect all pages/files (except for one) to new domain?
I have already made an .htaccess file that successfully redirects most all the different pages and files on my old domain (www.olddomain.com) to my new domain (www.newdomain.com).
However, I need one page to not be redirected to the new site, that page is the Google verification .html file:
http://www.olddomain.com/googleverification.html
I have attached the most relevant parts of the file (.htaccess) pasted below:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !.(php|html?|jpg|gif|png|pdf|tiff|bmp|ico|gz|zip|xml|txt)$
RewriteRule ^(.*)([^/])$ http://www.newdomain.com/$1$2/ [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Upvotes: 2
Views: 1465
Reputation: 58
I've been asking the same question on different forums and another solution also works.
I just thought to share it here also.
RewriteCond {HTTP_HOST} !^www.newdomain.com$
RewriteCond %{REQUEST_URI} !^/googleverification.html
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
Upvotes: 0
Reputation: 786349
Keep your first rule as:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/googleverification\.html [NC]
RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [L,R=301,NE]
Upvotes: 1