让 URL 动态看起来不错
如果我有数据库驱动的页面,其 url 如下所示:
http://www.companyname.com/dynamic_page.php?id=1
http://www.companyname.com/dynamic_page.php?id=2
http://www.companyname.com/dynamic_page.php?id=3
...
http://www.companyname.com/dynamic_page.php?id=4001
http://www.companyname.com/dynamic_page.php?id=4002
http://www.companyname.com/dynamic_page.php?id=4003
url 中的 id 用于从数据库获取正确的内容,并且用户可以添加/删除/编辑任意数量的页面。
我了解如何手动使用 mod_rewrite 使网址看起来更好,例如
http://www.companyname.com/individual/1
http://www.companyname.com/individual/2
http://www.companyname.com/individual/3
...
http://www.companyname.com/commercial/4001
http://www.companyname.com/commercial/4002
http://www.companyname.com/commercial/4003
但是我将如何动态地做到这一点?即允许用户指定 url 的一部分,在这种情况下,用户选择了“个人”或“商业”,然后在 url 末尾添加 id,而无需我每次都编辑 .htaccess 文件用户创建新页面,或编辑/删除页面。
Possible Duplicate:
How do I convert a PHP query string into a slash-based URL?
If I have database driven pages with urls like this:
http://www.companyname.com/dynamic_page.php?id=1
http://www.companyname.com/dynamic_page.php?id=2
http://www.companyname.com/dynamic_page.php?id=3
...
http://www.companyname.com/dynamic_page.php?id=4001
http://www.companyname.com/dynamic_page.php?id=4002
http://www.companyname.com/dynamic_page.php?id=4003
Where the id in the url is used to get the correct content from the database, and the user has the ability to add/remove/edit as many pages as s/he wants.
I understand how to manually use mod_rewrite to give the urls a nicer look e.g.
http://www.companyname.com/individual/1
http://www.companyname.com/individual/2
http://www.companyname.com/individual/3
...
http://www.companyname.com/commercial/4001
http://www.companyname.com/commercial/4002
http://www.companyname.com/commercial/4003
But how would I do that dynamically? i.e. allow the user to specify part of the url, in this case the user has selected either "individual" or "commercial", then add the id at the end of the url, without me having to edit the .htaccess file each and everytime a user makes a new page, or edits/deletes a page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这已经足够了:
/4441之前是什么并不重要,它总是会导致dynamic_page.php?id=4441...
I think that this could be enough:
It doesn't matter what is before /4441, it will always lead to dynamic_page.php?id=4441...
您是否手动为 ht access 文件中的每个 ID 添加新行?
您可以使用正则表达式轻松完成所有这些。这是一篇有点旧的帖子,但完全符合您的需求:http://www.webmasterworld。 com/forum92/4332.htm
Are you manually adding a new line for every ID in the ht access file?
You could accomplish all of this easily with a regular expression. Here's a post that's a bit old but is completely relative to your needs: http://www.webmasterworld.com/forum92/4332.htm
试试这个:
Try this:
查看-> 清理网址
你可以尝试一下。
Check out -> Clean Urls
You can try.