【问题标题】:htaccess redirect subfolder to another without using root htaccesshtaccess 将子文件夹重定向到另一个而不使用 root htaccess
【发布时间】:2017-12-21 11:36:20
【问题描述】:

我整天都在寻找解决方案。

所以我的一个朋友使用可怕的 web builder 在根目录中构建了一个基本网站。无论出于何种原因,web builder 将其文件粘贴在 /site 子文件夹中,并且它持有根 htaccess 人质。对 web builder 的任何更改都会覆盖 htaccess。

现在,她有两个子文件夹。子 1 和子 2。我们需要尝试访问 sub1 以重定向到 sub2。我习惯于将以下代码放在根 htaccess 中:

# Enable rewriting.
RewriteEngine on
RewriteRule ^/?sub1/(.*)$ /sub2/$1 [R,L]

但如前所述,网络构建器将在她发布任何更改时删除所有这些内容。我在 sub1 中放置了一个新的 htaccess 文件,其中包含以下文本:

Redirect 302 / http://example.com/sub2

重定向子文件夹,但不正确。由于某种我无法弄清楚的原因,它实际上重定向到 http//example.com/sub2sub1。

我觉得解决方案就在我面前,但我想不通。

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    您可以使用RedirectMatch Directive

    RedirectMatch 302 /sub1/(.*) /sub2/$1
    

    【讨论】:

    • 谢谢!这很完美!它甚至会继承文件结构(以便 sub1/index.php=string 指向 sub2/index.php=string)。
    猜你喜欢
    • 2017-04-18
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2015-06-12
    • 2017-12-05
    相关资源
    最近更新 更多