2013-11-20 3 views
1

내 사이트 디렉토리에 대한 규칙을 작성하려고합니다. PHP 파일에 대해서만 mod_rewrite 규칙을 작성하는 방법

나는이 같은 시도 :

RewriteEngine on 

RewriteRule ^(css|font|img|js)/([a-zA-Z0-9\/\.])$ $1/$2 [L] 

RewriteRule ^([a-zA-Z0-9\/\_]*)$ index.php?url=$1 [L] 

을하지만 잘 작동하지 않는 이유를 이해하지 못할.

1 - 나는 사용자가이 디렉토리 css|font|img|js에 직접 액세스 할 I 사용자가보기 디렉토리에 *.js|*.css 파일에 직접 액세스 할

2- (단지 파일이 아닌 디렉토리 목록을. 403.php에 디렉토리 목록을 다시 작성) . (다른되지 파일. 403.php에 다른 재 작성)

3- 나는 사전에 index.php?url=$1

덕분에 다른 모든 URL을 다시 작성합니다.

답변

1

당신의 패턴의이 부분 : /([a-zA-Z0-9\/\.])$ 정확히 하나의 편지의 문자, 숫자 슬래시 또는 점, 다음 말 다음에 슬래시를 의미한다. 나는 다음과 같은 것을 원한다고 생각합니다 :

ErrorDocument 403 /403.php 

RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(css|font|img|js)/ - [L,F] 

RewriteCond %{REQUEST_URI} !\.(js|css)$ 
RewriteRule ^view/ - [L,F] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA] 
1

이러한 규칙을 시도 할 수 있습니다 :

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule !^(css|font|img|js)/ /403.php [NC,L] 

RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_URI} \.(css|js)$ [NC] 
RewriteRule !^view/ /403.php [NC,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ index.php?url=$1 [L,QSA] 
1

RewriteCond을 사용하는 것은 어떻습니까?

당신은 같은 것을 할 수

:

RewriteEngine On 

RewriteCond %{REQUEST_URI} ^/(css|font|img|js)/ 
RewriteRule .* - [L] 

RewriteRule ^([a-zA-Z0-9\/\_]*)$ index.php?url=$1 [L] 

당신이 CSS를, 글꼴, IMGJS 디렉토리 내 파일에 대한 무 조작 재 작성을이 방법을하고 index.php을 다른 모든 URL에 대해 다시 작성하십시오. 사용 [L, NC는] 다른 페이지로 리디렉션하지 않는

1
RewriteEngine on 

Options -Indexes 

RewriteCond %{REQUEST_URI} .php$ [OR] 
RewriteRule ^(.*)$ target_file.php?=url$1 [L,NC] 

#allow access to file js and css 
RewriteCond %{REQUEST_URI} .(css|js)$ 
RewriteRule ^(.*)$ - [L,NC] 

: 당신은 로컬 호스트/page.php에 액세스하는 경우이 target_file.php로 리디렉션하지 않는

URL =/page.php

동일한 URL에서 계속 진행하고 target_file.php 파일

이 표시됩니다.
관련 문제