1
#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}\.php -f
#RewriteRule ^(.*)$ $1.php
RewriteEngine On
RewriteBase/
# Use the following rule if you want to make the page like a directory
RewriteRule ^user/(!(profile.php))$ user/$1/ [R=301,L]
# The following rule does the rewrite.
RewriteRule ^user/(.+)/$ profile.php?id=$1
# The following rewrite the other way round:
RewriteCond %{REQUEST_URI} ^/profile.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php
RewriteCond %{QUERY_STRING} id=([^&]+)
RewriteRule ^profile.php$ user/%1?
<files .htaccess>
order allow,deny
deny from all
</files>
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^(.*)$ "http\:\/\/mysite\.com\/$1" [R=301,L]
當我訪問此網址: http://mysite.com/user/john/ - 這完全完美的作品! 但是,當我存取權限的URL沒有斜槓結尾,就像這樣:http://mysite.com/user/john瀏覽器告訴我這個錯誤:的.htaccess做我的網址結尾沒有斜槓「未找到」
我應該怎麼做嗎?您的幫助將不勝感激,並獲得獎勵!
謝謝! :-)
所以你在這裏做的是強制URL在最後有一個斜槓,對吧? :) – PinoyStackOverflower 2012-08-13 03:30:20
@ElsonSolano是的,它看起來像你原來的規則是試圖做到這一點,而你的重寫規則'RewriteRule^user /(.+)/$ profile.php?id = $ 1'特別與尾部的斜線匹配,所以沒有它,沒有任何反應。 – 2012-08-13 03:36:54