使用.htaccess将子域设置为指向特定目录

时间:2014-05-07 17:55:29

标签: apache .htaccess dns subdomain

我想使用.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."

1 个答案:

答案 0 :(得分:0)

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

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