htaccess重写规则的模式匹配,涉及一个文件夹到另一个文件夹

时间:2013-08-01 10:32:32

标签: regex .htaccess pattern-matching

我需要一些快速帮助来清理htaccess文件的以下规则,因为列表已经很长了。

这是在网站迁移后发生的,这使得之前来自/browse/author/NAME-HERE的作者页面现在位于/by/NAME-HERE

当然有一种模式匹配这些或某种东西的方法吗?

Redirect /browse/author/some-person /by/some-person
Redirect /browse/author/another-person /by/another-person
Redirect /browse/author/some-other-person /by/some-other-person
Redirect /browse/author/yet-more /by/yet-more
Redirect /browse/author/ /

我想保留/browse/author/重定向到根目录,如果可能的话......

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

使用mod_rewrite绝对可以。

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^/?browse/author/(.*) /by/$1 [L,R=301,NC]