我需要可以将我的整个olddomain.com重定向到newdomain.com的htaccess代码,而无需重定向images文件夹,css文件夹和js文件夹,也无需重定向olddomain.com的主页[将作为我的登录页面] 尝试过此代码,但没有用。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain\.com$
RewriteCond %{REQUEST_URI} !^/images(/|$)
RewriteCond %{REQUEST_URI} !^/assets(/|$)
RewriteCond %{REQUEST_URI} !^/js(/|$)
RewriteRule ^$ https://newdomain.com [L,R=301]
答案 0 :(得分:1)
您可以使用此:
RewriteEngine on
RewriteCond ℅{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
#exclude /images folder
RewriteCond ℅{REQUEST_URI} !^/images/ [NC]
#exculde /css folder
RewriteCond ℅{REQUEST_URI} !^/css/ [NC]
#exclude /js folder
RewriteCond ℅{REQUEST_URI} !^/js/ [NC]
#exclude old domain homepage
RewriteCond ℅{REQUEST_URI} !^/$
#redirect everything else to new domain
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R,NE]
要将请求从您的旧域重定向到新域首页,只需将规则(最后一行)替换为此
RewriteRule ^(.*)$ http://newdomain.com/ [L,R,NE]