0

Just a quick question,

I am making user profiles for my website and would like to include vanity URLS, but the page has a lot of separate information which gets loaded, e.g Followers tab, uploads tab, and each of these have some kind of setting that can be applied like ASC DESC, New/old results etc. What would be the best way to have vanity urls but keep the functionality i require?

http://www.site.com/user.php?id=1&content=Followers&Order=(Different settings for each result)

But i am wondering if it would be better if i should just name the content differently if someone wanted to search for followers + a limitation, for example

http://www.site.com/user.php?id=1&content=NewestFollowers,

rather than

http://www.site.com/user.php?id=1&content=Followers&Order=Newest

4

1 回答 1

0

You typically want to construct the vanity URL so that it directly maps to query string parameters to the ugly URL. So if you have:

http://www.site.com/user.php?id=1&content=Followers&Order=Newest

You can make your vanity URL look like:

http://www.site.com/u/1/Followers/Newest/

But the /1/ bit is a little ugly, and not exactly vanity, so if you can pass a username through that query string parameter, it would look better:

http://www.site.com/u/jonlin/Followers/Newest/

Then you'd just put some mod_rewrite rules in an htaccess file in your document root that internally rewrites the vanity URL back to the ugly one:

RewriteEngine On
RewriteRule ^u/([^/]+)/([^/]+)/([^/]+)/?$ /user.php?id=$1&content=$2&Order=$3 [L,QSA]
RewriteRule ^u/([^/]+)/([^/]+)/?$ /user.php?id=$1&content=$2 [L,QSA]
RewriteRule ^u/([^/]+)/?$ /user.php?id=$1 [L,QSA]
于 2012-09-10T11:48:24.317 回答