【问题标题】:htaccess rewrite http to https and remove subdirectory from urlhtaccess 将 http 重写为 https 并从 url 中删除子目录
【发布时间】:2019-05-13 09:09:59
【问题描述】:

您好,我正在使用 Deployer 来部署 Craft CMS 网站。该站点符号链接到名为“当前”的目录。我正在使用 mod rewrite 从文档根目录中的 url 中删除 /current/public,如下所示:

RewriteEngine On
RewriteCond %{REQUEST_URI} !current/public/
RewriteRule (.*) /current/public/$1 [L]

在当前/公共文件夹中有这个 htaccess 来删除 index.php 并创建漂亮的 url:

RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]

编辑 - 测试

以下工作强制使用 HTTPS,但我的 url 看起来像这样: example.com/current/public/about 等

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]

如何调整它以强制网站始终使用 HTTPS?

【问题讨论】:

    标签: .htaccess mod-rewrite php-deployer


    【解决方案1】:

    这会将所有 http 请求重定向到 https。 重写引擎开启

    RewriteCond %{SERVER_PORT} 80

    RewriteCond %{HTTP_HOST} ^(www.)?yourdomainname.com

    重写规则 ^(.*)$ https://www.yourdomainname.com/$1 [R,L]

    希望对你有帮助

    【讨论】:

    • 谢谢你,但它给了我一个重定向循环
    【解决方案2】:

    以下是我设法开始的工作:

    RewriteEngine on
    RewriteRule ^(.*)$ current/public/$1
    RewriteCond %{HTTP:X-Forwarded-Proto} !=https
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
    

    【讨论】:

      猜你喜欢
      • 2020-01-09
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2012-06-25
      相关资源
      最近更新 更多