【问题标题】:Server redirection服务器重定向
【发布时间】:2021-05-28 07:02:54
【问题描述】:

我们想要从根域重定向到子文件夹

我们已经尝试过: '''

 RewriteCond %{HTTP_HOST} ^example.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.example.com$
  RewriteRule (.*)$ https://example.com/folder1/subfolder/$1 [R=301,L]

''' 重定向有效,但内部文件也会预先添加文件夹结构,因此网页无法按预期工作。

非常感谢您

【问题讨论】:

标签: apache .htaccess server subdomain


【解决方案1】:

您的问题是这些规则也适用于已包含重写文件夹结构的请求 URL。所以你需要为这些情况添加一个例外:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteCond %{REQUEST_URI} !^/folder1/subfolder/
RewriteRule (.*)$ https://example.com/folder1/subfolder/$1 [R=301,END]

如果可能,这些规则应该在实际的 http 服务器的主机配置中实现。当使用分布式配置文件(“.htaccess”)时,您需要接受性能损失...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 2021-04-29
    • 2018-04-13
    • 2010-12-04
    • 2015-03-21
    相关资源
    最近更新 更多