使用Apache的mod_rewrite去除URL子目录 [英] Using Apache mod_rewrite to remove sub-directories from URL
问题描述
的网址是以下格式的,我管理的Word preSS的一个实例:
I'm managing an instance of Wordpress where the URLs are in the following format:
http://www.example.com/example-category/blog-post-permalink/
博客作者没有加入类别的职位,因此,尽管他们中的一些在其网址有合法的范畴,至少有一半是未分类中不一致的工作。
The blog author did an inconsistent job of adding categories to posts, so while some of them had legitimate categories in their URLS, at least half are "uncategorized".
我可以很容易地改变字preSS呈现URL W / O类别名称(例如, http://www.example.com/blog-post-permalink/
),但我想创建一个的mod_rewrite规则为previous格式的任何请求自动重定向到新的,更清洁的。
I can easily change Wordpress to render the URL w/o the category name (e.g., http://www.example.com/blog-post-permalink/
), but I'd like to create a mod_rewrite rule to automatically redirect any requests for the previous format to the new, cleaner one.
你有一个很好的mod_rewrite的配方处理这个问题,同时考虑到我要兑现为真正的话语preSS目录是在我的根目录?
Do you have a good mod_rewrite recipe to handle this, taking into account that I want to honor requests for the real WordPress directories that are in my webroot?
推荐答案
作为东西
RewriteRule ^/[^/]+/([^/]+)/?$ /$2 [R]
也许会做吗?这简单的重新定位/富/酒吧/到/条
Perhaps would do it? That simple redirects /foo/bar/ to /bar
这篇关于使用Apache的mod_rewrite去除URL子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!