【问题标题】:using .htaccess to find subdomain files使用 .htaccess 查找子域文件
【发布时间】:2015-07-02 14:18:15
【问题描述】:

我有一个站点example.com,其文件位于/path/to/example/ 它有子域subdomain.example.com,其文件位于/path/to/example/subdomain/ 我如何使用.htaccess 提供这些文件而无需重定向?

我试过了

RewriteCond %{HTTP_HOST} ^subdomain.example.com
RewriteRule ^(.*)$ http://example.com/subdomain/$1 [L]

但这会将用户重定向到新页面。

我也试过

RewriteCond %{HTTP_HOST} ^subdomain.example.com
RewriteRule ^(.*)$ /subdomain/$1 [L]

但这会导致服务器错误。

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite subdomain


    【解决方案1】:

    试试这个规则:

    RewriteCond %{HTTP_HOST} =subdomain.example.com
    RewriteRule !^subdomain/ subdomain%{REQUEST_URI} [L,NC]
    

    【讨论】:

    • 这不会重定向 [good] 但会在 /path/to/example/ [bad] 处提供文件
    • 完美。你能解释一下(或让我解释一下)你的解决方案是如何工作的吗?
    • !^subdomain/ 是负匹配,这意味着如果当前 URI 不是以 /subdomain/ 开头,则将所有请求路由到 /subdomain/<uri>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 2011-02-20
    相关资源
    最近更新 更多