mod_rewrite 用于友好的 URL
我正在尝试将永久链接实现到我的内容管理系统中,但我似乎遇到了 mod_rewrite 的问题。我有一个 PHP 文件 (single.php
),它将根据传递给它的永久链接名称显示单个帖子。即post.php?permalink=name-of-post-here
。
以下是我设置的规则:
RewriteRule ^([0-9]{4})/([a-z]+)?$ $1/ [R]
RewriteRule ^([0-9]{4})/([a-z]+)?$ post.php?permalink=$1
另外,如何获取日期/年份
(即 2012 年),并将其分配为 PHP 文件的参数。 (即 post.php?year=2012?permalink=name-of-post-here
)所有这些都可以使用 mod_rewrite 来完成吗?
非常感谢。
想要将
http://www.website.com/post.php?year=2012&permalink=post-name-here
更改为
http://www.website.com/2012 /帖子名称-此处
I'm trying to implement Permalinks into my content management system and I seem to be stuck at a problem with mod_rewrite. I have a PHP file (single.php
) which will display a single post based on the Permalink name that gets passed through to it. i.e. post.php?permalink=name-of-post-here
.
Here are the rules I've set up:
RewriteRule ^([0-9]{4})/([a-z]+)?$ $1/ [R]
RewriteRule ^([0-9]{4})/([a-z]+)?$ post.php?permalink=$1
Also, how do I get the date/year
(i.e. 2012), and assign that as a parameter for the PHP file. (i.e. post.php?year=2012?permalink=name-of-post-here
) & can all of this be done using mod_rewrite?
Many Thanks.
Want to change
http://www.website.com/post.php?year=2012&permalink=post-name-here
to
http://www.website.com/2012/post-name-here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用以下代码:
如果您不希望外部重定向(在浏览器中更改 URL),请删除
R
标志。You should use this code:
If you don't want external redirect (change URL in browser) then remove
R
flag.