admin管理员组文章数量:1426058
When I started with my blog, the permalinks and following structure:
http://<domain>/%year%/%monthnum%/%day%/%postname%/
Some time ago, I changed the permalink structure to "http://<domain>/%postname%/
" only.
In order to tackle the external links to the old permalink structure, I added the following line in my htaccess-file:
RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://<domain>/$4
Now the problem is that the redirect line breaks the archive links, eg. "http://<domain>/2010/09/02
" is redirected to the front page instead of showing the posts from Sept 2, 2010.
Is it possible to correct the redirect directive in htaccess, or am I not going to be able to eat the cake and have it too?
When I started with my blog, the permalinks and following structure:
http://<domain>/%year%/%monthnum%/%day%/%postname%/
Some time ago, I changed the permalink structure to "http://<domain>/%postname%/
" only.
In order to tackle the external links to the old permalink structure, I added the following line in my htaccess-file:
RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://<domain>/$4
Now the problem is that the redirect line breaks the archive links, eg. "http://<domain>/2010/09/02
" is redirected to the front page instead of showing the posts from Sept 2, 2010.
Is it possible to correct the redirect directive in htaccess, or am I not going to be able to eat the cake and have it too?
Share Improve this question edited Feb 16, 2011 at 8:40 hakre 12.9k6 gold badges49 silver badges85 bronze badges asked Sep 4, 2010 at 15:36 TFMTFM 1227 bronze badges1 Answer
Reset to default 2RedirectMatch of Mod_Alias is not as powerful as Mod_Rewrite. If you have Mod_Rewrite on your host (Pretty Permalinks make use of it for example) you could make the redirect only if the URL is not in the Archive link format.
To test for that case, there is RewriteCond
and to make the redirect command, there is the RewriteRule ... [R=301]
directive.
An Example based on your data:
RewriteCond %{REQUEST_URI} !^/((20|19)[0-9]{2})/([0-9]{2})/[0-9]{2}$ [NC]
RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://<domain>/$4 [R=301,L]
This is untested but I think it should do the work. I've used quantifier ({2}) to better specifiy how many numbers you expect. Next to that in the RewriteCond I've created a pattern that only matches the 20.. and 19.. years.
The first line (the condition, RewriteCond
) checks not to match an Archive-URL and only if not matched, the rule to do the redirect will be executed. The RewriteRule
is basically doing the same as your RedirectMatch
directive.
本文标签: Change of permalink structureredirects in htaccess breaks the archive links
版权声明:本文标题:Change of permalink structure - redirects in htaccess breaks the archive links 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745390955a2656596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论