.htaccess从旧网站重定向到新网站

时间:2015-07-24 09:55:02

标签: regex apache .htaccess mod-rewrite

如何通过htaccess将旧链接重定向到新网站。我有这段代码:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www.mysite.co.uk$ [NC] 
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [R=301,L]

Redirect 301 /2013/08/ http://www.mysite.co.uk/whats-on/news/

是附加的正确吗?

1 个答案:

答案 0 :(得分:0)

请勿将mod_alias规则与mod_rewrite规则混合使用,并将特定重定向保留在通用规则之前。

RewriteEngine on

RewriteRule ^2013/08/ http://www.mysite.co.uk/whats-on/news/ [L,R=301]

RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.co\.uk$ [NC] 
RewriteRule ^(.*)$ http://www.mysite.co.uk/$1 [R=301,L]