2012-10-31 3 views
0

RewriteRules으로 디렉토리의 실제 파일을 모두 무시할 수 있습니까? 내 말은, "flatlinks"또는 "permalinks"(http://example.com/not/an/actual/file/path/)를 만들고 있다는 것입니다. 그 page.php가 처리합니다. 이것은 RewriteCond으로 다른 모든 파일을 '무시'하는 경우에만 작동합니다. 내 .htaccess 파일의 디렉토리에있는 모든 실제 파일에 대해 RewriteCond을 만드는 대신 실제 파일이 있는지 확인하고, 그렇지 않으면 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] 
관련 문제