使用htaccess将所有旧网址重定向到新网址

时间:2011-12-22 11:10:54

标签: .htaccess redirect http-status-code-301

我在liferay上实现了一个旧网站。所有链接都像

www.site.com/web/something

我想写一个htaccess规则,以便所有带/ web / *的请求都应该 被重定向到主页永久...

现在对于个人网址我写了这个。

Redirect 301 /web/contact http://www.site.com/contact

是否有通配符方法或其他内容?

2 个答案:

答案 0 :(得分:1)

如何将 / web / something 重定向到 http://site.com/something

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^web/(.*) http://site.com/$1 [R=301,L]
</IfModule>

或以/ web /重定向到主页的任何内容:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^web/.* http://site.com/ [R=301,L]
</IfModule>

答案 1 :(得分:0)

或者,保持在mod_alias中,您可以使用RedirectMatch来使用通配符:

RedirectMatch 301 /web/(.*) http://www.site.com/$1