以特定格式结尾的任何URL的重写

时间:2015-06-03 12:57:39

标签: .htaccess mod-rewrite

我想重定向以

结尾的所有网址

data.htmltemplates/data.php

info.htmltemplates/info.php

any_other_file.htmltemplates/index.php

同样,所有以这些名称结尾的网址(可以是http://some-domain.com/some/long/path/data.html

1 个答案:

答案 0 :(得分:2)

您可以在 /.htaccess 文件中使用此功能:

RewriteEngine On

# Internally rewrite data/info.html to the applicable PHP file
# in the templates directory
RewriteRule (data|info).html$ /templates/$1.php [NC,L]

# Rewrite everything else ending in .html to /templates/index.php
RewriteRule ^(.*).html$ /templates/index.php [NC,L]
相关问题