在啓用了SEF的Joomla網站中,我有關鍵字友好的網址,例如/ keyword/keyword。我需要重寫與index.php文件開始的所有URL,如/index.php/keyword/keywordApache RewriteRule [L]未被授予
我已經從後和核心的.htaccess規則與Joomla來臨之前嘗試添加一個有條件重寫規則:
## 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]
這裏是rewritelog:
[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]
看來[L]在第一重寫被忽略並且無論第二重寫被執行。我怎樣才能解決這個問題?
爲了澄清什麼,我希望發生:
http://test.com/index.php/keyword header redirect 301 -> http://test.com/keyword
http://test.com/keyword rewrite -> http://test.com/index.php/keyword
不幸的是,我得到完全相同的結果。如果我在這裏嘗試我的規則,並刪除E = HTTP_AUTHORIZATION:%{HTTP:Authorization}規則,那麼它就起作用。但在我的本地測試系統中刪除它並不能解決問題。 – jdog
那麼你在瀏覽器中輸入的URL是什麼以及你看到了什麼錯誤? – anubhava
我輸入http://test.com/keyword/keyword並重定向到http://test.com,這是不正確的。 – jdog