【问题标题】:How to use Apache .htaccess to redirect to another folder如何使用 Apache .htaccess 重定向到另一个文件夹
【发布时间】:2013-10-07 07:33:21
【问题描述】:

我想从旧文件夹重定向到新文件夹。

我想将http://domain.com/old/* 网址重定向到http://domain.com/new/*。

我发现了一个问题:Redirect folder to another with htaccess

我尝试在文档根目录中编写一个 .htaccess,仅在上述问题的答案中给出以下代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/old/(.*)$ /new/$1 [L,NC,R=302] 

我还在 httpd.conf 文件中启用了 mod_rewrite。但我仍然无法让 apache 从旧文件夹重定向到新文件夹。

我还检查了 apache 错误日志,我得到的只是以下错误:

[error] [client x.x.x.x] File does not exist: <documentroot>/old

【问题讨论】:

  • ^/old/(.*)$ 应该是^old/(.*)$
  • @hjpotter92 我试过了,但仍然遇到同样的错误
  • @hjpotter92:重写指令不起作用,因为 AllowOverwrite 指令设置为无。设置为All,使指令生效。

标签: apache .htaccess mod-rewrite


【解决方案1】:

如果您希望从old 请求的所有内容都被定向到new,我会跳过使用med_rewrite 而是使用Redirect

<Directory />
    Redirect permanent /old /new
</Directory>

您可以根据需要跳过permanent(指定重定向代码)。但是,为了能够使用本地 URL,您需要运行 Apache >= 2.2.6。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-12
    • 2013-02-01
    • 2015-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-24
    • 2016-03-23
    相关资源
    最近更新 更多