.htaccess从1个网址(无论是什么文件/文件夹)重定向到另一个网址

时间:2012-02-26 18:00:58

标签: .htaccess redirect

我有一个网站http://rochesterwaterskishow.com,他们最近更改了名称,因此他们希望将自己的网址更新为http://skidox.com。我正在尝试将任何页面从rochesterwaterskishow.com重定向到skidox.com/site/index。

我有这行代码可以将http://rochesterwaterskishow.com重定向到http://skidox.com,但是如果我转到http://rochesterwaterskishow.com/test之类的内容,它就不会重定向到http://skidox.com

RewriteRule ^$ http://skidox.com/site/index [R=301,L]

我怎样才能把它变成一个所有东西,所以rochesterwaterskishow.com/*被重定向到skidox.com/site/index?

更新:完整.htaccess文件

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

RewriteRule ^$ http://skidox.com/site/index [R=301,L]

2 个答案:

答案 0 :(得分:1)

这是因为搜索模式^ $只匹配URI路径“/”。您需要在匹配变量中获取请求,例如:

RewriteCond %{HTTP_HOST} rochesterwaterskishow
RewriteRule ^.*          http://skidox.com/site/index/$0     [R=301,L]

我假设你正在为新网站使用SEO优化式URI。如果您只想将所有重定向到索引页面而没有任何上下文,那么仍然需要一个匹配的模式:

RewriteCond %{HTTP_HOST} rochesterwaterskishow
RewriteRule ^            http://skidox.com/site/index        [R=301,L]

更新完整htaccess后的帖子

RewriteEngine on
RewriteBase   /

RewriteCond %{HTTP_HOST}        rochesterwaterskishow
RewriteRule ^.*                 http://skidox.com/$0  [R=301,L]

RewriteCond $0                  ^(index\.php$|robots\.txt$|resources)
RewriteRule ^.*                 -                     [S=1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$              index.php/$1          [L,QSA]

答案 1 :(得分:0)

RewriteRule ^$ http://skidox.com/site/index/$1 [R=301,L]