htaccess重写规则博客链接

时间:2013-05-24 15:46:59

标签: .htaccess mod-rewrite

我一直在使用htaccess来删除重写某些网址,但是我现在正在寻找一些更复杂的东西。

我们的网站博客(WordPress)过去常常有这样的链接:

/博客/ postname / 1387

然而,在重做网站后,我们的链接现在只是

/ postname

是否可以从/ blog / postname / 1387重定向任何用途,并通过htaccess删除最后的博客和号码,以便它只包含帖子名称?目前我有:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^blog/(.*)/.*$ $1/
</IfModule>

很想听到任何提示或提示,因为这实际上没有做任何重定向,我做错了什么?

1 个答案:

答案 0 :(得分:1)

让我们做一点清理:

<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On

#Rewrites are all relative to /
RewriteBase /

#Explicit - If the request is for index.php, do nothing.
RewriteRule ^index\.php$ - [L]

#Conditional – Unless the file or directory specifically exists,
#If the request is for the old style blog URI, redirect to new style and stop.
#Otherwise, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/.*$ $1/ [R=301,L,QSA]
RewriteRule . /index.php [L]
</IfModule>