【发布时间】:2016-06-24 15:50:37
【问题描述】:
这是我目前拥有的 htaccess 文件...
setEnv HTTP_TARGET_PAGE %{REQUEST_FILENAME}
ErrorDocument 404 default
ErrorDocument 301 default
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
#the below line doesn't work
RewriteCond %{REQUEST_URI} *.php
#the above line doesn't work
RewriteRule ^.*$ ./index.php
我试图让每个 php 文件或不存在的文件请求管道通过 index.php 进行处理。所有其他 php 文件有时都包含在 index.php 中(使用网址)。
所以我的 index.php 中可能有某个地方
if($my_url = "www.example.com/potato"){
require_once("potato.php");
}
但我不希望他们输入“http://www.example.com/potato.php”并直接获取 php,而不需要标题等。我的 htaccess 不能正常工作(那一行每次都会出错)。但我不想重写所有内容,因为图像文件将无法正常工作。我该如何解决?
【问题讨论】:
-
致 Popnoodles、3dgoo、Milap、Alex Tartan 和不走运的......不同的问题有不同的解决方案。您链接到的解决方案会重写所有内容。我只是试图重写 .php 请求和未找到的文件,您链接到的文件几乎会重写所有内容。
标签: php apache .htaccess mod-rewrite