0

「_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」フォルダにあります。1つ上のレベルには、すべてのリクエストを「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
4

2 に答える 2

-1

実際の問題を修正する場合としない場合があるランダムな修正を次に示します。これは完全には明確ではなく(私のコメントを参照)、サーバーを制御してRewriteLogを有効にすると役立つ可能性があります。

RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9

ただし、これをメインサーバー構成に配置する必要があります。

そうは言っても、2つの主な問題:

  • 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を使用できるかどうかについては、まだ説明していません(使用できないと思います)

于 2009-06-24T00:43:36.713 に答える