2011-10-01 4 views
4

.htaccess를 통해 파일 확장명을 숨기고 직접 액세스를 거부하는 방법을 찾고 있습니다. 의는 다음 사항을 고려하자 파일 확장자를 다시 작성하지만 파일에 직접 액세스를 거부하지 않습니다.

http://www.xyz.zyx/index.php 

는 지금까지

http://www.xyz.zyx/index OR http://www.xyz.zyx/ 

모든 좋은 변환됩니다. 사용자가 직접 액세스를 시도하면 차단 또는 리디렉션됩니다. 예, URL에 사용자 유형은, 블록을 다음 (확장) 바 또는 리디렉션 경우 :

http://www.xyz.zyx/index.php 

내가 다른 질문에서 다른 답을 확인하지만 비는 정확히 것 같았다.

저와 같은 초보자를 도와 주심에 미리 감사드립니다. 하나 그런 일의 유용성에 의문을 제기 할 수 있지만

+0

가능한 중복 ([* .PHP는 URL을 청소 리디렉션] http://stackoverflow.com/q/2267488/), [URL 확장자를 숨기십시오. mod_rewrite] (http://stackoverflow.com/q/6241408/) – outis

답변

5

, 그것은 그래서 여기으로 가능 mod_rewrite를 사용하여 .htaccess에서 그것을 할 방법은 다음과 같습니다의

RewriteEngine On 

# Sets your index script 
RewriteRule ^$ index.php [L] 

# Condition prevents redirect loops (when script is not found) 
RewriteCond %{ENV:REDIRECT_STATUS} !^$ 
RewriteCond %{REQUEST_FILENAME} !-f 

# Stop here if the file is not found after a redirect 
RewriteRule ^(.*)$ notfound.php [L] 

# Condition prevents redirect loops (when script is found) 
RewriteCond %{ENV:REDIRECT_STATUS} ^$ 

# Forbid access directly to PHP files 
RewriteRule ^.*?\.php$ forbidden [F,L] 

# Make sure the filename does not actually exist (images, etc.) 
RewriteCond %{REQUEST_FILENAME} !-f 

# Append the .php extension to the URI 
RewriteRule ^(.*)$ $1.php [L] 
관련 문제