更改永久链接 - 需要 htaccess 代码
我有一个博客(wordpress 版本 3.01),它具有以下格式的基于自定义的永久链接:/%category%/%postname%/
。例如,blog.com/category/post-name/
。
我需要将永久链接更改为“日期和名称”/%year%/%monthnum%/%day%/%postname%/
(我的主题要求它才能正常工作)。
我需要在 .htaccess 文件中写入什么以使旧的永久链接 301 重定向到新的永久链接?
我的网站已有 9 个月的历史,约有 500 篇文章。
示例
/%category%/%postname%/ 到 /%postname%/
RedirectMatch 301 ^/([^/]+)/([^/]+)/$ http://www.mydomain.com/$2
我的情况是将此
/%category%/%postname%/ 发送到/%year%/%monthnum%/%day%/%postname%/
RedirectMatch 301 ????????????
I have a blog (wordpress version 3.01) which has custom based permalinks in the following format: /%category%/%postname%/
. For example, blog.com/category/post-name/
.
I need to change permalinks to "Day and name" /%year%/%monthnum%/%day%/%postname%/
(my Theme requires that to work properly).
What do I need to write in my .htaccess file to make the old permalinks 301 to redirect to the new ones?
My site is 9 months old and has about 500 articles.
Example
/%category%/%postname%/ to /%postname%/
RedirectMatch 301 ^/([^/]+)/([^/]+)/$ http://www.mydomain.com/$2
My case is to get this
/%category%/%postname%/ to /%year%/%monthnum%/%day%/%postname%/
RedirectMatch 301 ???????????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用
.htaccess
文件执行此操作,因为可以执行此操作的重写功能 (RewriteMap) 在.htaccess
上下文中不起作用。但是,由于您有一个封闭列表,因此有一个固定的类别列表,因此将它们映射到通用重定向器脚本很简单:(将猫列表扩展为完整的类别列表)。那么
redirector.php
是一个标准的重定向器模式。您只需在退出之前查询您的 WordPress D/B 即可确定要发布的帖子的 YMD。
You cant do this with an
.htaccess
file as the rewrite feature (RewriteMap) which could do this doesn't work in a.htaccess
context. However, since you've got a closed list and therefore a fixed list of categories, it is simple to map these to a common redirector script:(extending the cat list to be a complete list of categories). Then
redirector.php
is a standard redirector pattern. You simply query your Wordpress D/B to determine the YMD for the post to issue abefore exiting.