2013-02-14 83 views
1

我有下面的代码,这需要网址,如“www.example.com/foo”,它改写为“www.example.com/html/foo.php”htaccess的 - 测试重写URL

RewriteCond %{REQUEST_FILENAME} !-d [NC] 
RewriteRule ^([^\.]+)$ html/$1.php [NC] 

我想修改这个,如果重写的url:'www.example.com/html/foo.php'不存在,URL会被重写为'www.example.com/html/fallback.php?查询=富'

我一直在绕圈走了几个小时。任何解决方案

回答

2

你可以尝试做该文件存在先检查(使用-f)然后事后做,你必须重写:

RewriteCond %{REQUEST_FILENAME} !-d [NC] 
RewriteCond %{REQUEST_FILENAME} !-f [NC] 
RewriteCond %{REQUEST_URI} ^([^\.]+)$ 
RewriteCond %{DOCUMENT_ROOT}/html/%1.php !-f 
RewriteRule^html/fallback.php?query=%1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^\.]+)$ html/$1.php [L] 
+0

完美的作品 - 非常感谢! – hunter 2013-02-14 23:31:20