使用.htacces将子域重定向到特定目录

时间:2015-07-31 03:53:40

标签: php apache .htaccess mod-rewrite redirect

我之前遇到过问题并提出了这个问题:PHP Image Upload using POST

我发现问题的原因是我的域重定向。我在我的域面板中使用了重定向(服务器模拟),无法处理文件上传。

通过搜索解决方案,我发现了这一点:sub-domain directory redirection using htaccess

我启用了mod_rewrite模块并尝试了这个.htacces文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.de$
RewriteRule ^(.*)$ http://domain.de/sub/directories/$1 [R=301,L]

subdomain.domain.de的A-DNS条目设置为我的服务器的IP。我的服务器的根目录需要验证,但我希望子域指向的目录不需要。我不确定重定向是否有效,但是当我打开子域时,它会要求进行身份验证。

如何在不让用户进行身份验证的情况下将子域重定向到服务器上的另一个目录?

2 个答案:

答案 0 :(得分:1)

在这种情况下,您必须将virtualHost用于子域,因为您的基本HTTP身份验证在htaccess之前执行。
另一种方法,你可以在RewriteRule之后在htacess文件中配置基本的HTTP身份验证,不要在apache配置文件中配置。

答案 1 :(得分:0)

按照本指南,我可以使用虚拟主机执行我想要的操作:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

我还必须删除.htaccess文件。除了在新站点 - 可用配置文件中更改ServerAlias / Name和DocumentRoot之外,我不得不改变任何内容。