使用.htaccess(而不是重定向)使用文件代替丢失的文件

时间:2016-01-20 14:49:39

标签: php apache .htaccess mod-rewrite

我正在尝试使用服务器上的另一个文件代替列表文件zindex.php该文件必须像在该位置实际存在一样运行。我想我可以用.htaccess做到这一点但是在淘网之后,我没有资源去做这件事。这甚至可能吗?

RewriteEngine On

RewriteCond $1 !^files
RewriteCond %{REQUEST_URI} custom_link_
RewriteRule .* zindex.php

1 个答案:

答案 0 :(得分:1)

这将执行zindex.php而不是index.php作为您放置.htaccess的文件夹

RewriteEngine On

RewriteRule ^index.php$ zindex.php

# /index.php              will execute /zindex.php
# /index.php?query=string will execute /zindex.php //$_GET['query'] === 'string'
# /                       will execute /zindex.php
# /folder/index.php       will execute /folder/index.php