简体   繁体   English

Apache虚拟主机重定向到文档根目录

[英]Apache Virtual Host redirect to document root directory

I have successfully set the DocumentRoot for a given server names: 我已经为给定的服务器名称成功设置了DocumentRoot:

<VirtualHost *:80>
 DocumentRoot "/var/www/html/domain1"
 ServerName www.domain1.com
 ServerAlias *.domain1.com
#Other directives here
</VirtualHost>

I can't seem to figure out, how to move the subfolders ie."www.domain1.com/contact-us" so it presents index.html located in "/var/www/html/domain1". 我似乎无法弄清楚如何移动子文件夹,即“ www.domain1.com/contact-us”,因此它显示位于“ / var / www / html / domain1”中的index.html。

I tried adding the alias for the /contact-us in the VirtualHost instructions: 我尝试在VirtualHost说明中为/ contact-us添加别名:

<VirtualHost *:80>
     DocumentRoot "/var/www/html/domain1"
     ServerName www.domain1.com
     ServerAlias *.domain1.com
    #Other directives here
     Alias /contact-us /var/www/html/domain1
    </VirtualHost>

It doesn't work as expected. 它没有按预期工作。

I am thinking doing this via .htaccess in the subfolder for the domain1. 我正在考虑通过domain1子文件夹中的.htaccess进行此操作。 How would I go around redirecting everything after the domain name to the index.html? 如何将域名后的所有内容重定向到index.html?

RewriteEngine on
RewriteRule ^subdirectory/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^about-us/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^contact/(.*)$ /$1 [R=301,NC,L]
RewriteRule ^subfolder/(.*)$ /$1 [R=301,NC,L]

Test out this code, make sure the change the folder names. 测试此代码,确保更改文件夹名称。


EDIT 编辑

This must be in your .htaccess in your web directory root folder. 该名称必须位于Web目录根文件夹中的.htaccess中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM