在启用了SEF的Joomla网站中,我有关键字友好的网址,例如/ keyword / keyword。我需要重写所有以index.php开头的网址,例如/index.php/keyword/keyword
我尝试在Joomla随附的核心.htaccess规则之前和之前添加条件RewriteRule:
SAXDocumentHandler.endElement (name)
这是rewritelog:
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
#rewrite all urls starting with index.php
RewriteCond %{REQUEST_URI} ^/index.php
RewriteRule ^index.php(.*?)$ /$1 [R=302,L]
似乎忽略了第一次重写时的[L],并且无论如何都执行第二次重写。我该如何解决这个问题?
澄清我期望发生的事情:
[Tue Jun 23 11:19:35.986104 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] strip per-dir prefix: /home/jochen/projects/acgwebsite/trunk/nz/nzic -> nz/nzic
[Tue Jun 23 11:19:35.986118 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] applying pattern '.*' to uri 'nz/nzic'
[Tue Jun 23 11:19:35.986137 2015] [rewrite:trace5] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] setting env variable 'HTTP_AUTHORIZATION' to ''
[Tue Jun 23 11:19:35.986150 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] add path info postfix: /home/jochen/projects/acgwebsite/trunk/nz -> /home/jochen/projects/acgwebsite/trunk/nz/nzic
[Tue Jun 23 11:19:35.986162 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] strip per-dir prefix: /home/jochen/projects/acgwebsite/trunk/nz/nzic -> nz/nzic
[Tue Jun 23 11:19:35.986177 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] applying pattern '.*' to uri 'nz/nzic'
[Tue Jun 23 11:19:35.986192 2015] [rewrite:trace4] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] RewriteCond: input='/nz/nzic' pattern='!^/index\\.php' => matched
[Tue Jun 23 11:19:35.986215 2015] [rewrite:trace4] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] RewriteCond: input='/home/jochen/projects/acgwebsite/trunk/nz' pattern='!-f' => matched
[Tue Jun 23 11:19:35.986234 2015] [rewrite:trace4] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] RewriteCond: input='/home/jochen/projects/acgwebsite/trunk/nz' pattern='!-d' => matched
[Tue Jun 23 11:19:35.986246 2015] [rewrite:trace2] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] rewrite 'nz/nzic' -> 'index.php'
[Tue Jun 23 11:19:35.986262 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] add per-dir prefix: index.php -> /home/jochen/projects/acgwebsite/trunk/index.php
[Tue Jun 23 11:19:35.986277 2015] [rewrite:trace2] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] strip document_root prefix: /home/jochen/projects/acgwebsite/trunk/index.php -> /index.php
[Tue Jun 23 11:19:35.986291 2015] [rewrite:trace1] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f48292070a0/initial] [perdir /home/jochen/projects/acgwebsite/trunk/] internal redirect with /index.php [INTERNAL REDIRECT]
[Tue Jun 23 11:19:35.986353 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] strip per-dir prefix: /home/jochen/projects/acgwebsite/trunk/index.php -> index.php
[Tue Jun 23 11:19:35.986385 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] applying pattern '.*' to uri 'index.php'
[Tue Jun 23 11:19:35.986403 2015] [rewrite:trace5] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] setting env variable 'HTTP_AUTHORIZATION' to ''
[Tue Jun 23 11:19:35.986420 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] strip per-dir prefix: /home/jochen/projects/acgwebsite/trunk/index.php -> index.php
[Tue Jun 23 11:19:35.986432 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] applying pattern '.*' to uri 'index.php'
[Tue Jun 23 11:19:35.986450 2015] [rewrite:trace4] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] RewriteCond: input='/index.php' pattern='!^/index\\.php' => not-matched
[Tue Jun 23 11:19:35.986463 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] strip per-dir prefix: /home/jochen/projects/acgwebsite/trunk/index.php -> index.php
[Tue Jun 23 11:19:35.986478 2015] [rewrite:trace3] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] applying pattern '^index.php(.*?)$' to uri 'index.php'
[Tue Jun 23 11:19:35.986495 2015] [rewrite:trace4] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] RewriteCond: input='/index.php' pattern='^/index.php' => matched
[Tue Jun 23 11:19:35.986511 2015] [rewrite:trace2] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] rewrite 'index.php' -> '/'
[Tue Jun 23 11:19:35.986527 2015] [rewrite:trace2] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] explicitly forcing redirect with http://acgwebsite.example.com/
[Tue Jun 23 11:19:35.986540 2015] [rewrite:trace1] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] escaping http://acgwebsite.example.com/ for redirect
[Tue Jun 23 11:19:35.986554 2015] [rewrite:trace1] [pid 25526] mod_rewrite.c(468): [client 127.0.0.1:40592] 127.0.0.1 - - [acgwebsite.example.com/sid#7f483be32210][rid#7f4829214bf8/initial/redir#1] [perdir /home/jochen/projects/acgwebsite/trunk/] redirect to http://acgwebsite.example.com/ [REDIRECT/302]
答案 0 :(得分:1)
L
仅结束当前规则,导致mod_rewrite
再次遍历.htaccess。
您需要的是实际重新排序规则,以便在重写之前保持重定向:
## Begin - Joomla! core SEF Section.
#rewrite all urls starting with index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php(.*)$ $1 [R=302,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
确保在清除浏览器缓存后对其进行测试。
答案 1 :(得分:0)
我建议您使用ErrorDocument而不是尝试将其与重写规则一起使用:
## Begin - Joomla! core SEF Section.
#
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
ErrorDocument 404 /index.php