我想将所有不包含“_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”文件夹中。在上面一层,我有一个 .htaccess 将所有请求重定向到“v2”。

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
有帮助吗?

解决方案

你<!>#8217;使用错误的字符,¦断条,U + 00A6)代替|垂直线, U + 007C),以及REQUEST_URI的错误模式。

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

或者 v2 目录中的.htaccess文件:

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