【发布时间】:2016-11-11 06:18:49
【问题描述】:
我对 .htaccess 文件了解不多,需要一些帮助。我有几个网站托管了一个 CPanel 帐户。我不想将我的“主”站点直接存储在 public_html 文件夹中,所以我将它移到了一个子文件夹中,然后找到了这个 .htaccess 配置,它允许我从该子目录加载我的主站点。所以这行得通。
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/example_directory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /example.com/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
正如我所说,上面的 .htaccess 将允许我将我的站点文件存储在不同的文件夹中,而不是直接存储在根目录中。但现在我也试图通过 https 强制重定向该站点。我在这里找到了这个网站:
但是,由于我真的不理解 .htaccess 文件,我无法将这两个功能集成在一起。对此的任何帮助将不胜感激。谢谢。
【问题讨论】: