.htaccess仅在目标不存在时重定向

时间:2015-01-20 15:08:36

标签: php apache .htaccess mod-rewrite redirect

我正在尝试使用.htaccessexample.com/short之类的网址命名为example.com/short.php,但是当我测试配置时,我只会在请求不支持PHP脚本的PHP脚本时重定向。存在。例如:页面short.php已存在但shor.php在我请求example.com/short的页面时尚未显示example.com/short的404页面,但是当我请求{{1}时我得到了example.com/shor

的404页面

我正在使用的example.com/shor.php是:

.htaccess

1 个答案:

答案 0 :(得分:1)

.htaccess

中使用它
RewriteEngine on
Options -MultiViews

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^s/([A-Za-z0-9-]+)/?$ short.php?code=$1 [NC,L]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php [NC,L]
相关问题