简体   繁体   中英

How can I .htaccess 301 redirect all pages/files (except for one) to new domain?

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

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]

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM