【问题标题】:Rewriting a subdomain to root/subdomain将子域重写为根/子域
【发布时间】:2018-07-08 01:53:01
【问题描述】:

我目前有以下位置:localhost/dir1/ex.html

我正在尝试实现dir1.localhost/ex.html 映射到第一个网址的情况。以下 .htaccess 规则有效:

RewriteCond %{HTTP_HOST} =dir1.localhost
RewriteRule ^(.*)$ http://localhost/dir1/$1 [L]

但是,这不是我想要的,因为它很明显会重定向。我想保持网址不变(dir1.localhost)。

如何去做这件事?非常感谢。

【问题讨论】:

    标签: regex apache .htaccess url-rewriting


    【解决方案1】:

    如果您希望您的子域在内部指向该文件夹,请从您的规则目标中删除主机名:

    RewriteCond %{HTTP_HOST} =dir1.localhost
    RewriteCond %{REQUEST_URI} !^/dir1
    RewriteRule ^(.*)$ /dir1/$1 [L]`
    

    【讨论】:

    • 遗憾的是,这给了我一个 500 错误(Apache 错误日志指的是:AH00124 - Request exceeded limit of 10 internal redirects)。我已经尝试过使用 localhost 和一些我在 hosts 文件中临时设置的乱码域(包括子域)。这会是由于配置错误吗?到目前为止,我以前的 .htaccess 规则运行良好(是的,我在测试时删除了这些规则)。
    • 绝对完美。非常感谢 Starkeen!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 2016-11-20
    • 2017-07-04
    • 2020-02-03
    • 2012-01-25
    • 1970-01-01
    相关资源
    最近更新 更多