开发者

question title in url like stackoverflow

开发者 https://www.devze.com 2023-03-13 18:56 出处:网络
Id like to make a url similar to stackoverflow where the user can type in a textbox and then on refresh a url is created.like the url to this question uses the title i typed in. id like to make that e

Id like to make a url similar to stackoverflow where the user can type in a textbox and then on refresh a url is created. like the url to this question uses the title i typed in. id like to make that effect on my own sit开发者_开发问答e. thanks. I think this may have to incorporate a .htaccess file??


You may notice that the words from the title in the question URL don't affect where the URL goes. The following link goes to the same place: https://stackoverflow.com/questions/6366169/foo-bar-baz

All you need to do is make your server process respond to the URL in the correct way. How you do this will depend on your chosen server architecture and/or programming language. Using .htaccess is unrelated.


maybe this link will help you understand how you can achieve your goal https://docs.djangoproject.com/en/dev/topics/http/urls/ (django)

http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/ (php)

other web frameworks operate in similar way

in the given example you can interpret the url http://stackoverflow.com/posts/9701416/edit like this:

if you find "posts" in the url the next part of the url (9701416) is a parameter and the last part is the action so your main controller will load a post with id 9701416 and it will be loaded in edit mode (it doesn't mean there's a sub directory questions with sub directory 6366169 with a file "post")

0

精彩评论

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

关注公众号