Htaccess url重定向错误

时间:2016-08-08 13:47:14

标签: .htaccess

我的htaccess文件中有以下结构。我的问题是,如果URI根据规则与条件URL重定向匹配,如果URI不匹配,则应该应用默认规则,请告诉我如何修复。

第一条规则:RedirectMatch 301 /mob/(.*) http://www.newdomain.com/price/$1

默认规则:RedirectMatch 301 /(.*) http://www.newdomain.com/$1

当我尝试使用此默认规则覆盖其他规则时。

1 个答案:

答案 0 :(得分:0)

Assuming both domains are on the same root folder and host:

RewriteCond %{HTTP_HOST} ^originaldomain\.com$
RewriteCond %{REQUEST_URI} ^/cms
RewriteRule ^(.*)$ https://differentdomain.com/$1 [L,R=302]
If they are not on the same root and folder:

RewriteCond %{REQUEST_URI} ^/cms
RewriteRule ^(.*)$ https://differentdomain.com/$1 [L,R=302]
Now the 2nd part if the url is not a act, url, system or post:

RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/(act\?(.*)|url|system)$ [NC]
RewriteCond %{THE_REQUEST} !^POST [NC]
RewriteRule ^(.*)$ http://originaldomain.com/$1 [L,R=302]
Basically this should work, if it does after you test change to 302 to 301 if needed.