2012-10-31 116 views
0

是否可以使用RewriteRules来忽略目录中的所有实际文件?我的意思是,我正在创建page.php处理的“flatlinks”或“permalinks”(http://example.com/not/an/actual/file/path/)。这只适用于如果我忽略所有其他文件与RewriteCond。而不是创建一个RewriteCond为在我的.htaccess文件目录中的每个真实文件是否有办法告诉它检查是否有一个实际的文件显示,如果不让page.php照顾它?使用.htaccess“忽略”文件

RewriteCond %{REQUEST_URI} !^/index\.php$ 
RewriteCond %{REQUEST_URI} !^/somefile\.php$ 
RewriteCond %{REQUEST_URI} !^/someotherfile\.php$ 
RewriteCond %{REQUEST_URI} !^/page\.php$ 
RewriteRule ^([^/]*)$ /page.php?p=$1 [L] [NC] 

回答

1

下面表明,只有当所请求的文件(-f)或文件夹(-d)不存在(!)重定向,应执行磁盘上:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]*)$ /page.php?p=$1 [L,NC] 
+0

作品一种享受!你是第一个,所以你可以得到答案。 – bwoogie

1

是的,这是非常可能的。现有的代码之前添加这些行:

## If the request is for a valid directory 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
## If the request is for a valid file 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
## If the request is for a valid link 
RewriteCond %{REQUEST_FILENAME} -l 
## don't do anything 
RewriteRule^- [L]