子域映射到子目录



我有一个web应用程序,需要有每个公司的动态子域。这个网站也有SSL。我在Ubuntu VPS上使用apache。我所做的就是像

这样设置虚拟主机
<VirtualHost *:80>
    ServerName domain.com
    ServerAlias *.domain.com
    Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:443>
    ServerName domain.com
    ServerAlias *.domain.com
    ..........
    .................
</VirtualHost>

将流量定向到SSL是可以的。

所以我现在需要做的是我有一个文件夹"/app"在我的web根目录。我希望所有的子域直接到那个特定的文件夹,并在地址栏上显示相同的url。

我在php中启用了http_proxy模块,并创建了。htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*).domain.com
RewriteRule ^(.*)$ http://domain.com/app/$1 [P,NC,QSA]

当我访问"https://test.domain.com"这重定向到"https://domain.com/app/index.php"。我知道为什么会发生这种情况,因为当htaccess重定向到"http://domain.com/app/index.php"时,我的虚拟主机配置看到一个非SSL请求,它将请求重定向到与SSL相同的地址。所以我把。htaccess改成了

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*).domain.com
RewriteRule ^(.*)$ https://domain.com/app/$1 [P,NC,QSA]

我在重写规则中添加了"https"。当我再次访问"https://test.domain.com"时,它给了我这个错误。

Internal Server Error
The server encountered an internal error or misconfiguration and was     
unable to complete your request.
Please contact the server administrator at webmaster@localhost to 
inform them of the time this error occurred, and the actions you 
performed just before this error.
More information about this error may be available in the server error 
log.
Apache/2.4.7 (Ubuntu) Server at kjdcndkj.domain.com Port 443

最后我想要的是

1) redirect any Non-SSL trafic to SSL
2) any *.domain.com to /app folder

有人能帮我一下吗

谢谢。

试试这个:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC] 
RewriteRule ^(.*)$ %1/$1 [L]

最新更新