我有一些文件在/templates/。假设我得到request/templates/something.html。我想检查实际文件/templates/something.html是否存在并打印它。否则,我希望我的脚本/search_here.php做一些工作并打印特殊的输出。
我在我的htaccess文件中使用以下内容。它的工作几乎很好,唯一的问题是,在情况下search_here.php做的工作,我看到一个很好的输出,但服务器发送404头(HTTP/1.1 404 Not Found)。我怎么能关闭这个头(我的/search_here.php将打印这个头在需要的情况下)?
如有任何帮助,不胜感激。
RewriteEngine on
Options +FollowSymlinks
#RewriteBase /
RewriteCond %{REQUEST_URI} !/templates/
RewriteRule ^.*$ index.php [L]
ErrorDocument 404 /search_here.php
您不应该使用/search_here.php
作为404处理程序。
你可以使用:
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule !^templates/ index.php [L,NC]
RewriteRule ^ search_here.php [L]