如何使用.htaccess将指定的文件扩展名重定向到其他站点

时间:2012-02-27 01:56:11

标签: .htaccess mod-rewrite redirect request

我需要将扩展​​名为 .html 的所有文件重定向到不带 .html 扩展名的相同位置。无论从哪个位置请求,例如:

  • /file1.html ---> http:///mysite.com/file1/
  • /file2.html ---> http:///mysite.com/file2/
  • /file3.html ---> http:///mysite.com/file3/
  • /file4.html ---> http:///mysite.com/file4/

谢谢。

2 个答案:

答案 0 :(得分:2)

尝试将以下内容添加到站点根目录中的.htaccess文件中。

RewriteEngine on
RewriteBase /
RewriteRule ^(.+)\.html$ $1/ [L,NC,R=301]

答案 1 :(得分:0)

这应该有效:

RewriteRule ^/?(.+)\.html$ http://http:///mysite.com/$1/ [R,L]