使用.html和w / o .html永久重定向网址

时间:2011-10-29 01:31:26

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

我正在通过.htaccess进行一些永久的网址重定向

我使用以下代码:

Redirect permanent /someurl.html http://thedomain.com/newurl.html

我希望将重定向应用于以.html结尾并以非.html结尾的网址

例如

Redirect permanent /someurl.html http://thedomain.com/newurl.html
Redirect permanent /someurl http://thedomain.com/newurl.html

如果没有这两行,怎么能实现这一点(有缩写的方法)?

谢谢,

3 个答案:

答案 0 :(得分:2)

我不确定您是否可以在Redirect语句中使用正则表达式,但如果可以的话,这应该可行:

Redirect permanent /someurl(.html)? http://thedomain.com/newurl$1

如果你不能,那么这样的RewriteRule应该起作用:

RewriteRule ^someurl(.html)?$ http://thedomain.com/newurl$1 [L,R=301]

答案 1 :(得分:2)

您可以改用RedirectMatch directive。它等同于Redirect,但使用正则表达式。

您的规则如下:

RedirectMatch permanent someurl($|\.html) http://thedomain.com/newurl.html

希望它有所帮助。

答案 2 :(得分:1)

或者您只需按文件夹

重定向即可
Redirect permanent /one http://example.com/two

喜欢这样

在此阅读文档/手册。 http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirect