how to simplify the url

删除回忆录丶 提交于 2019-12-04 05:37:33

问题


Hi: In my website I found that their url are very simple like:

http://example.com/questions/4486620/randomaccessfile-probelm

And generally the url should like:

http://example.com/questions?xx=4486620&title=randomaccessfile-probelm

That's to say there is no request parameters combined by "&" in the url.

How did they make it? Is there any framework?

UPDATE: My application works under tomcat.


回答1:


On an apache web server you can do this using mod_rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Here is an example along with a tutorial...

The Apache rewrite engine is mainly used to turn dynamic url’s such as www.yoursite.com/product.php?id=123 into static and user friendly url’s such as www.yoursite.com/product/123

Read more about htaccess And mod_rewrite Tutorial by Blogstorm SEO Blog

RewriteEngine on
RewriteRule ^product/([^/\.]+)/?$ product.php?id=$1 [L]
Another example, rewrite from:
www.yoursite.com/script.php?product=123 to www.yoursite.com/cat/product/123/

RewriteRule cat/(.*)/(.*)/$ /script.php?$1=$2

Read more here that example by the way is copied from http://www.blogstorm.co.uk/htaccess-mod_rewrite-ultimate-guide/ - assigned kudos!



来源:https://stackoverflow.com/questions/4529552/how-to-simplify-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!