如何使用 apache 将子文件夹重写为另一个?
How to rewrite subfolder to another using apache?
我需要将 www.example.com/blog-ie
重写为 www.example.com/blog
,问题是因为它是一个博客,有些 url 看起来像 www.example.com/blog-ie/2015/05/some-article
,所以我不确定如何保持 URL 的其余部分完好无损。
将此放入您的 .htaccess
或 VirtualHost
RewriteEngine On
RewriteRule blog-ie(.*) /blog [R,L]
首先,RewriteEngine被激活。重写规则基本上告诉 httpd 执行以下操作
When an URL beginning with "blog-ie" is called, take everything following that URL ((.*)
) and append it (</code>) to "/blog". Send a redirect to the client (<code>R
) and let this rule be the last one evaluated (L
) if it matches.
通过规则第一部分(匹配部分)中的括号,您告诉 RewriteEngine 记住括号内的所有内容。这称为匹配组。在规则的第二部分,重写部分,第一个匹配组可以用</code>引用。如果你有更多的匹配组,你可以用 <code>
等引用它们。这种定义匹配组并在以后使用它们的方式称为反向引用。
我需要将 www.example.com/blog-ie
重写为 www.example.com/blog
,问题是因为它是一个博客,有些 url 看起来像 www.example.com/blog-ie/2015/05/some-article
,所以我不确定如何保持 URL 的其余部分完好无损。
将此放入您的 .htaccess
或 VirtualHost
RewriteEngine On
RewriteRule blog-ie(.*) /blog [R,L]
首先,RewriteEngine被激活。重写规则基本上告诉 httpd 执行以下操作
When an URL beginning with "blog-ie" is called, take everything following that URL (
(.*)
) and append it (</code>) to "/blog". Send a redirect to the client (<code>R
) and let this rule be the last one evaluated (L
) if it matches.
通过规则第一部分(匹配部分)中的括号,您告诉 RewriteEngine 记住括号内的所有内容。这称为匹配组。在规则的第二部分,重写部分,第一个匹配组可以用</code>引用。如果你有更多的匹配组,你可以用 <code>
等引用它们。这种定义匹配组并在以后使用它们的方式称为反向引用。