我如何.htaccess 301将所有页面/文件(一个除外)重定向到新域? [英] How can I .htaccess 301 redirect all pages/files (except for one) to new domain?

查看:66
本文介绍了我如何.htaccess 301将所有页面/文件(一个除外)重定向到新域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何.htaccess 301将所有页面/文件(一个文件除外)重定向到新域?

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

我已经制作了一个.htaccess文件,该文件可以成功重定向大多数我的旧域(www.olddomain.com)上的所有不同页面和文件到我的新域(www.newdomain.com)。

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).

但是,我需要一页要不重定向到新站点,该页面就是Google验证.html文件:

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

我已粘贴文件(.htaccess)中最相关的部分如下:

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]

这篇关于我如何.htaccess 301将所有页面/文件(一个除外)重定向到新域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆