【发布时间】:2010-10-07 21:57:00
【问题描述】:
我正在尝试为我的 wordpress 博客设置 SEO 友好的 URL,同时仍然可以灵活地随意更改帖子的标题。
我的永久链接结构是这样的:
%post_id%/%postname%
但是,我希望 wordpress 在寻找合适的帖子时只考虑 URL 中的 %post_id%(有点像 stackoverflow 上的这里)
例如:
https://stackoverflow.com/users/810/crossbrowser 与 https://stackoverflow.com/users/810/hello-world
相同我希望所有这些都指向同一个帖子,即 id 为 345 的帖子:
http://myblog.com/345/the-name-of-the-post
http://myblog.com/345/any-text
http://myblog.com/345
文档中提到了我正在尝试做的事情:Long permalinks,但我无法让它工作。
这是我的 .htaccess 文件:
RewriteEngine on
RewriteBase /
# Let wordpress use pretty permalinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# From the example in the documentation
#RewriteRule /post/([0-9]+)?/?([0-9]+)?/?$ /index.php?p=$1&page=$2 [QSA]
更新
我一直在这个online regular expression testing tool 中尝试这个 RewriteRule,但是当我把它放在我的 .htaccess 中时它不起作用(就在 RewriteBase 之后):
RewriteRule ^([0-9]+)/?([a-zA-Z0-9\-]+)/?$ index.php?p=$1 [QSA]
【问题讨论】:
标签: regex wordpress .htaccess seo permalinks