gpt4 book ai didi

.htaccess - 强制 https,强制到子文件夹,强制 www,不要破坏站点

转载 作者:行者123 更新时间:2023-12-04 15:27:08 27 4
gpt4 key购买 nike

我一直很难编辑我的 .htaccess 文件来一起做这三件事。我已经能够分别获得每个部分,但我只是不明白逻辑流程如何使它们全部工作。

这是我能够使用 bluehost support 上的演示进行整合的最好方法
http://helpdesk.bluehost.com/index.php/kb/article/000347

我感谢任何帮助解决此问题。

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# Bluehost.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/folder/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /folder/$1
# Change yourdomain.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 folder, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
RewriteRule ^(/)?$ folder/index.php

RewriteCond %{HTTP_HOST} ^sampleurl\.com$ [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.sampleurl.com/$1 [L]

# For security reasons, Option all cannot be overridden.
# Options All -Indexes
# Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes

更新:

很长一段时间后,我遇到了以下问题。
IndexIgnore *
RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/site/
RewriteRule (.*) https://www.example.com/$1 [L,R]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]

新问题。
  • Bluehost 有一个应用程序可以快速安装和更新开源应用程序,如 wordpress、joomla、phpbb 等。显然我的新 super .htaccess 文件完全破坏了他们的系统。我可以运行更新和安装的唯一方法是将 .htaccess 移动到 .htaccess.bak 直到升级或安装完成。然后把它移回去。
  • 我无法在我托管在其他目录中的其他站点上创建任何 .htaccess。例如我有一个存储在/www/site/中的主帐户,该脚本将请求强制到该帐户中。不幸的是,我存储在/www/site2/和/www/site3/中的其他站点无法正常工作。首先,我必须创建一个空白的 .htaccess 以防止它拉出上面在/www/中找到的 .htaccess。出于某种原因,如果我尝试执行诸如强制 www.site2.com 之类的操作,我会收到 500 错误,说我正在强制进行太多重定向。

  • 我有一个理论,我上面的解决方案需要更具体一点,以确保它只影响发送到 example.com 的请求。 (我认为任何不包含/site/的内容都有些宽泛)。

    我感谢任何支持解决这个问题。会让我有点头疼!

    更新二:

    我不相信我可以访问 apache 配置。我在 cpanel 中看到的唯一选项是 apache 处理程序(不太确定该部分是做什么的)。

    我将提交一张票以查看 simplescripts 服务器从哪个位置运行。我相信它来自“https://www.simplescripts.com”。您建议我添加什么编辑以忽略此域?

    我的主机 bluehost 以主帐户和子域启动您。主帐户的位置设置为 user\www。不幸的是,当您尝试托管多个域时,这会变得困惑。这就是为什么我使用 .htaccess 强制将命中该目录的请求放入\site\目录。从而将主站点捕获到\site\目录中。

    我认为我在一个子域中遇到的重定位问题是由于 wordpress 试图强制一个没有 www 的域,然后我编写了一个 .htaccess 文件来强制使用 www。这导致了无限循环,而不是该线程所涉及的我的 .htaccess 文件。如果我能解决 simplescripts 问题,我就是 gmoney ;)

    最佳答案

    我认为这样的事情会奏效

    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} !^/folder/
    RewriteRule (.*) https://www.example.com/folder/$1 [L,R]

    RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} ^/folder/
    RewriteRule (.*) https://www.example.com/$1 [L,R]

    但我承认我没有测试过。如果需要,您可以添加所有不重定向(如果文件存在)等。

    如果您还没有看过,这里是 mod_rewrite documentation .

    编辑:

    回应更新的问题:

    我注意到的第一件事是,您似乎对您的设置有足够的控制权,可以将重写放在 Apache 配置文件(在 VirtualHost 部分)而不是 htaccess 文件中,这将立即解决您与其他站点的问题。

    第一个问题,听起来您需要添加 RewriteCond 以排除 Bluehost 软件使用的任何 URL。要么,要么在不同的 VirtualHost 下访问 Bluehost 软件(一旦您将重写内容放入 VirtualHost 块中)。

    如果您无法编辑 Apache 配置,那么其他站点的最简单修复方法是不要将它们设为主站点的子目录(在文件系统上)。反正也挺奇怪的。将您的主站点移至 /www 的子目录如果需要,也可以。

    就我个人而言,我把所有网站都放在 /srv/www/com.site-name.www在我的服务器上(也就是说,逆序,顶级域在前,当按字母顺序排序时,它将相关的东西组合在一起。例如,当你有 www.example.com 和 static.example.com 时)

    关于.htaccess - 强制 https,强制到子文件夹,强制 www,不要破坏站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4729888/

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