【问题标题】:Setup subdomain to point to a specific directory using .htaccess使用 .htaccess 设置子域以指向特定目录
【发布时间】:2014-05-07 17:55:28
【问题描述】:

我想使用 .htacces 将子域指向不同的路径 sub.domain.co.uk 指向服务器路径 /htdocs_sub/ www.domain.co.uk 指向服务器路径 /htdocs_www/

我正在尝试:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.domain\.co\.uk$

RewriteCond %{REQUEST_URI} !^/htdocs_sub/

RewriteRule (.*) /htdocs_sub/$1

RewriteCond %{HTTP_HOST} ^www\.domain\.co\.uk$

RewriteCond %{REQUEST_URI} !^/htdocs_www/

RewriteRule (.*) /htdocs_www/$1

</IfModule>

没有正确响应,只是:

"Forbidden
You don't have permission to access / on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

【问题讨论】:

    标签: apache .htaccess dns subdomain


    【解决方案1】:
    RewriteCond %{HTTP_HOST} ^([a-z\d]+)\.domain\.co\.uk$
    RewriteCond %{REQUEST_FILENAME} !^/htdocs_
    RewriteRule . /htdocs_%1%{REQUEST_FILENAME} [L]
    

    假设所有路径都相对于文档根目录

    【讨论】:

      猜你喜欢
      • 2014-02-25
      • 1970-01-01
      • 2015-10-22
      • 2011-08-05
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      相关资源
      最近更新 更多