我不知道這一點,當我在測試我的規則:HTACCESS和[PT]標誌忽略通過url傳遞的一部分?
http://htaccess.madewithlove.be/
它指出,應該工作。
我使用這個網址:
http://site.com/uk/en/clients/1/view
Options +FollowSymlinks
RewriteEngine on
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteRule ^(.+[^/](?!\.php))$ $1/ [QSA,PT]
#language
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !lang
RewriteRule ^([a-z]{2})/([a-z]{2})(?:/(.*)|)$ /$1/$3?lang=$2 [NC,QSA,PT]
#country
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !country
RewriteRule ^([a-z]{2})(?:/(.*)|)$ /$2?country=$1 [NC,QSA,PT]
#keyword
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/(.*)/$ /$2?keyword=$1&test=$2 [NC,QSA,PT]
#without actions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php !-f
RewriteCond %{QUERY_STRING} !keyword
RewriteRule ^([^/]+)/(.*)$ /$2?keyword=$1 [NC,QSA,PT]
#id
RewriteCond %{QUERY_STRING} !id
RewriteRule ^([^/]+)/(.*)$ /$2?id=$1&test2=$2 [NC,QSA,PT]
#actions
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php !-f
RewriteCond %{QUERY_STRING} !action
RewriteRule ^/(.*)$ /?action=$1 [NC,QSA,PT]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /$ /index.php [NC,QSA,L]
目前,然而,它終止在ID,這是什麼是輸出:
Array ([id] => view [test2] => [keyword] => clients [test] => 1/view [country] => uk [lang] => en)
我根本看不出來爲什麼它會忽略1 /並將ID設置爲view?
非常感謝,我現在完全理解mod_rewrite的工作方式了。我認爲它只是將字符串傳遞給下一步。 – 2012-03-26 08:19:33