gpt4 book ai didi

.htaccess - 更改根文件夹目录并使用 .htaccess 重定向到 HTTPS

转载 作者:太空宇宙 更新时间:2023-11-03 14:44:09 26 4
gpt4 key购买 nike

我不太了解 .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 强制重定向该网站。我在这里找到了这个网站:

Force Website to Use SSL

但是,由于我真的不理解 .htaccess 文件,所以我在将这两个功能集成在一起时遇到了麻烦。对此的任何帮助将不胜感激。谢谢。

最佳答案

我很确定这是我自己想出来的。我只需要将它添加到我的 .htaccess 文件的末尾:

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

它就像一个魅力。完整的 .htaccess 文件如下所示,它更改了站点要使用的文件夹目录,然后强制通过 https。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example_directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

关于.htaccess - 更改根文件夹目录并使用 .htaccess 重定向到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40531224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com