2011-09-13 58 views
2

網站如何使用實際的URL位置作爲參數?網站如何使用實際的網址作爲參數?

例子:

Parameter = www.mysite.com/search.php?q=parameter 
URL = www.mysite.com/s/parameter 

又如:

Parameter = www.mysite.com/user.php?uid=someid 
URL = www.mysite.com/users/username 

他們如何防止一個404錯誤,而是把該URL '結尾' 作爲參數? 任何答案讚賞,但PHP優先。

更新:您是如何設置這取決於您的託管服務提供商?

回答

1

隨着mod_rewrite

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^s/(.*)$ search.php?q=$1 [L] 
RewriteRule ^users/(.*)$ users.php?uid=$1 [L] 

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]