php:SEO 友好的 url
我正在开发一个新项目,我想为此网站创建 SEO 友好的 URL,例如
mysite.com/first_content、mysite.com/second_content。 URL 必须是动态的,这意味着 URL 必须与内容标题相关。我怎样才能做到这一点?是否可以使用 htacess?
谢谢
I am working on a new project, I want to create SEO friendly URL's for this site like
mysite.com/first_content, mysite.com/second_content. URL's must be dynamic which means URL's must related to the content title. How can I done this ? Is is possible to use htacess, ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.htaccess 的示例规则(一旦您确保启用了 mod_rewrite):
这些规则匹配任何不存在的文件的 URL,并将其传递到您的脚本。
Sample rules for .htaccess (once you make sure mod_rewrite is enabled):
These rules match any URL that isn't an already existing file and passes it to your script.
是的,您可以通过使用
.htaccess
来做到这一点。互联网上有大量教程。用于执行此操作的模块称为
mod_rewrite
。它根据正则表达式模式重新路由传入请求。这些教程很好地解释了这一点:
1. URL 重写初学者指南
2. http://www.easymodrewrite.com/guide-syntax
您还需要如果您打算使用 mod_rewrite,请了解正则表达式的基础知识。该网站是最好的正则表达式资源之一。
- 正则表达式教程
Yes, you can do that by using
.htaccess
for that. There are plenty of tutorials available on Internet.The module used to do that is called
mod_rewrite
. It re-routes incoming requests based on regular expression patterns.These tutorials explains it pretty well:
1. A Beginner's Guide to URL Rewriting
2. http://www.easymodrewrite.com/guide-syntax
You will also need to know the basics about regular expressions if you plan to use mod_rewrite. This site is one of the best regular expression resources out there.
- Regular Expression Tutorial
在 .htaccess 中:
其中 $2 包含第二个括号的内容。
In .htaccess:
Where $2 has the content of the second parentheses.
试试这个:
Try this: