Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 重写以特定格式结尾的任何URL的规则_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess 重写以特定格式结尾的任何URL的规则

.htaccess 重写以特定格式结尾的任何URL的规则,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我想重定向所有以 data.html到templates/data.php info.html到templates/info.php any_other_file.html到templates/index.php 同样,所有以这些名称结尾的URL(可能是http://some-domain.com/some/long/path/data.html)您可以在/.htaccess文件中使用此选项: 重新编写引擎打开 #在内部将data/info.html重写为适用的PHP文件 #在模板目录中 重写规

我想重定向所有以

data.html
templates/data.php

info.html
templates/info.php

any_other_file.html
templates/index.php


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

您可以在
/.htaccess
文件中使用此选项:

重新编写引擎打开
#在内部将data/info.html重写为适用的PHP文件
#在模板目录中
重写规则(data | info).html$/templates/$1.php[NC,L]
#将以.html结尾的所有内容重写为/templates/index.php
重写规则^(.*).html$/templates/index.php[NC,L]

您尝试过什么?这真的很简单……我已经成功地将所有文件重定向到
template/index.php
,使用以下规则:
RewriteRule^(.*)$template/index.php[NC,L]
,但这就是我所能做的一切。这很好!请再说一件事:我如何让任何url进入templates/index.php?不仅仅是那些以.html结尾的;当然,除了data&info.html之外,我想我知道了,只是从最后一行删除了
.html