RewriteEngine On
RewriteBase/
# Use the following rule if you want to make the page like a directory
RewriteRule ^(v)$ /$1/
# The following rule does the rewrite.
RewriteRule ^(.+)/$ profile.php?name=$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} name=([^&]+)
RewriteRule ^profile.php$ %1?
我在我的.htaccess文件做上面這段代碼,這是因爲之前,我profile.php顯示的是這種URL的工作正常,在我的profile.php頁:的.htaccess多個規則
http://mysite.com/profile.php?name=john
但是當我寫的代碼是這樣的結果:
http://mysite.com/john/
我也想這個代碼適用於我的category.php,所以我所做的只是複製上面的代碼和我的整個的.htaccess文件看起來像這樣:
RewriteEngine On
RewriteBase/
# Use the following rule if you want to make the page like a directory
RewriteRule ^(v)$ /$1/
# The following rule does the rewrite.
RewriteRule ^(.+)/$ profile.php?name=$1
RewriteRule ^(.+)/$ category.php?cid=$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} name=([^&]+)
RewriteRule ^profile.php$ %1?
RewriteCond %{REQUEST_URI} ^/category.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /category.php
RewriteCond %{QUERY_STRING} cid=([^&]+)
RewriteRule ^category.php$ %1?
但這個代碼給了我一個奇怪的結果,因爲當我訪問 http://mysite.com/john/
說我看到的是我的category.php內容的內容。
我應該在這裏做什麼?任何幫助將不勝感激和獎勵!
謝謝!
系統應如何知道什麼是名稱和類別?你需要首先定義。 – jeroen
@jeroen我的類別的URL是這樣的: http://mysite.com/category.php?id=1雖然我的個人資料是這樣的:http://mysite.com/profile.php?id= 1 – PinoyStackOverflower
是的,但是你的改寫的網址是'mysite.com/john /'和'mysite.com/movies /'。什麼在新的url中定義了一個類別以及什麼名字? – jeroen