문제

"_js", "_ css", "_img"등을 포함하지 않는 모든 URL을 내 디스패치 스크립트로 리디렉션하고 싶습니다. 어떻게 든 작동하지 않습니다. 예를 들어, / _js / 폴더 내의 모든 파일은 접근 할 수 없습니다 (의미 : 해당 폴더에있는 실제 파일로 이동하는 대신 index.php로 전송됩니다).

여기 내 htaccess가 있습니다.

IndexIgnore *
Options +FollowSymLinks
RewriteEngine on

# if the following conditions are met, SKIP the rewriteRules.

RewriteCond %{REQUEST_URI} ^/(_admin/¦_css/¦_js/¦_img/)
RewriteRule . - [S=9]


# Externally redirect to add missing trailing slash
RewriteRule ^(([a-z0-9._\-]+/)*[a-z0-9_\-]+)$ http://%{HTTP_HOST}/$1/?%{QUERY_STRING} [NC,R,L]

# SIX PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&title=$6&%{QUERY_STRING} [NC,L]

# FIVE  PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&%{QUERY_STRING} [NC,L]

# FOUR PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&%{QUERY_STRING} [NC,L]

# THREE PARAMS : projects/touch/texts/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&%{QUERY_STRING} [NC,L]

# TWO PARAMS: downloads
RewriteRule ^downloads/([^/]+)/$ index.php?section=downloads&item=$1&%{QUERY_STRING}  [NC,L]

# TWO PARAMS:
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&%{QUERY_STRING} [NC,L]

# TAG URL : index.php?tag=space%2C+navigable+music#5
RewriteRule ^tag/([a-z0-9_\-]+)/$ index.php?tag=$1&%{QUERY_STRING} [NC,L]
# ONE PARAM
RewriteRule ^([a-z0-9_\-]+)/$ index.php?section=$1&%{QUERY_STRING} [NC,L]

편집하다:

내 폴더 구조에 유의하십시오. 문제가 발생할 수 있습니까?

"v1"및 "v2"폴더 구조가 있습니다. 이 .htaccess는 "v2"폴더에 있습니다. 위의 한 레벨에는 모든 요청을 "v2"로 리디렉션하는 .htaccess가 있습니다.

root 
  L.htaccess << dispatch between v1 and v2 folders 
  L v1 L v2 L.htaccess << the .htaccess code posted above 
  L _admin L all my website files & folders
도움이 되었습니까?

해결책

당신은 잘못된 캐릭터를 사용하고 있습니다. ¦ (깨진 막대, U+00A6) 대신 | (수직선, u+007c) 및 잘못된 패턴 REQUEST_URI.

RewriteCond %{REQUEST_URI} ^/v2/(_admin/|_css/|_js/|_img/)
RewriteRule . - [S=9]

또는 귀하의 .htaccess 파일의 경우 v2 디렉토리 만 :

RewriteRule ^_(admin|css|js|img)/ - [S=9]

다른 팁

다음은 실제 문제를 해결하거나 수정할 수있는 몇 가지 랜덤 수정 사항입니다.이 문제는 완전히 명확하지 않으며 (내 의견 참조) 서버를 제어하고 RewriteLog를 통해 다음을 통해 도움이 될 수 있습니다.

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

그러나 이것을 기본 서버 구성에 넣어야합니다.

즉, 두 가지 주요 문제 :

  • QSA 플래그 사용 부족 (실제로 관련이 없음)
  • 슬래시 사용 과도

수정 된 파일이 있습니다

IndexIgnore *
Options +FollowSymLinks
RewriteEngine on

# if the following conditions are met, SKIP the rewriteRules.

RewriteCond %{REQUEST_URI} ^(_admin¦_css¦_js¦_img)
RewriteRule . - [L]


# Externally redirect to add missing trailing slash. Not really needed, AFAICS
# RewriteRule ^(([^/]+/)*[^/]+)$ http://%{HTTP_HOST}/$1/ [NC,R,L,QSA]

# SIX PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5&title=$6 [NC,L,QSA]

# FIVE  PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4&id=$5 [NC,L,QSA]

# FOUR PARAMS
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3&content=$4 [NC,L,QSA]

# THREE PARAMS : projects/touch/texts/
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2&menu=$3 [NC,L,QSA]

# TWO PARAMS: downloads
RewriteRule ^downloads/([^/]+)/?$ index.php?section=downloads&item=$1  [NC,L,QSA]

# TWO PARAMS:
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?section=$1&item=$2 [NC,L,QSA]

# TAG URL : index.php?tag=space%2C+navigable+music#5
RewriteRule ^tag/([^/]+)/?$ index.php?tag=$1 [NC,L,QSA]
# ONE PARAM
RewriteRule ^([^/]+)/?$ index.php?section=$1 [NC,L,QSA]

편집 : 폴더 구조가 설명 된 경우 처음에 v2 .htaccess에 추가하십시오.

RewriteBase /

RewriteLog를 사용할 수 있거나 사용할 수 없다면 아직 설명하지 않았습니다 (나는 당신이 할 수 없다고 가정합니다)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top