htaccess重定向所有页面/变量/路径除外

时间:2014-01-16 11:03:57

标签: regex apache .htaccess mod-rewrite

从子域移动

http://randy.savage.com

http://www.randy.com

我希望http://randy.savage.com/path/path/path 也将被转移到新的域名。

除外

http://randy.savage.com/you/are/pretty

http://randy.savage.com/maybe/dance

那些应该像他们一样

怎么办呢?

1 个答案:

答案 0 :(得分:1)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^randy\.savage\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(you/are/pretty|maybe/dance) [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule ^ http://www.randy.com%{REQUEST_URI} [L,NE,R=301]