.htaccess htaccess重写规则博客链接

.htaccess htaccess重写规则博客链接,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我一直在使用htaccess删除和重写某些URL,但是我现在看到的东西有点复杂 我们的网站博客(WordPress)过去有如下链接: ​/博客​/邮政编码/1387 然而,在重做网站后,我们的链接现在只是 /邮名 是否有可能从中重定向任何用途​/博客​/postname/1387,然后通过htaccess删除最后的blog和编号,这样它就只包含postname了?目前我有: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /

我一直在使用htaccess删除和重写某些URL,但是我现在看到的东西有点复杂

我们的网站博客(WordPress)过去有如下链接:

​/博客​/邮政编码/1387

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

/邮名

是否有可能从中重定向任何用途​/博客​/postname/1387,然后通过htaccess删除最后的blog和编号,这样它就只包含postname了?目前我有:

<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>

重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
重写规则^blog/(.*)/.$$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>

#打开发动机
重新启动发动机
#重写都是相对于/
重写基/
#显式-如果请求是index.php,则不执行任何操作。
重写规则^index\.php$-[L]
#有条件–除非文件或目录明确存在,
#如果请求是针对旧式博客URI的,则重定向到新样式并停止。
#否则,重定向到index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^blog/(.*)/.$$1/[R=301,L,QSA]
重写规则/index.php[L]

不确定为什么需要
^index\.php$-[L]
/index.php[L]
。您是否尝试过删除它们,并使您的重写规则显示为
RewriteRule^blog/(.*)/.$$1/[L,QSA]
?索引规则是WordPress默认添加到其中的,您确定我可以删除它们吗?似乎是多余的-
%{REQUEST\u FILENAME}-f
是一个有条件的说法,“如果文件还不直接存在,请执行以下操作”。然后
/index.php[L]
是一个“Last”指令,它可能会阻止
^blog/(.*)/.$$1/
甚至触发“如果它不是真实的文件或目录,请重定向到index.php”。你至少应该把你的重写规则放在那条之前。感谢你的想法,Stslavik,不幸的是,当我尝试转到它时,它不起作用。它根本没有重定向,你可能知道它为什么没有做任何事情吗?试着在[L,QSA]前面添加
R=301,
,如上所述。在mamp上测试。。。因为我没有类似的设置,这有点像在黑暗中刺伤:)