开发者

How do sites use an actual URL as a parameter?

How do sites use an actual URL location as a parameter?

Example:

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

Another Example:

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

开发者_JAVA技巧How do they prevent a 404 error and instead treat the URL 'ending' as a parameter? Any answer is appreciated but php preffered.

UPDATE: Is how you set this up dependent on your hosting provider?


This is commonly known as "routing", and is a feature of many frameworks.

It is facilitated by a web server configuration (see mod_rewrite on Apache) that internally rewrites any URL not matching an actual file to the index of the folder above it, and so on.

See also: http://knol.google.com/k/seo-friendly-url-or-pretty-url-using-apache-mod-rewrite#


With 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] 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜