gpt4 book ai didi

.htaccess - htaccess 中的 https 和规则顺序(使用表达式引擎)

转载 作者:行者123 更新时间:2023-12-04 06:02:45 26 4
gpt4 key购买 nike

我正在表达式引擎中构建一个站点,该站点的一部分需要是 https。该站点还使用了一个新域名(新的 www.example-new.com 旧的 www.example.old.com)。

我想做以下事情:

  • 删除 index.php
  • 强制 www
  • 对任何以 www.example.old.com/extranet 开头的网址强制使用 https
  • 重定向不是 www.example.old.com/extranet 的 https URL(例如 www.example.old.com/news 到 http

  • 到目前为止,我有以下代码适用于前两个要求:
        <IfModule mod_rewrite.c>
    RewriteEngine On
    # Force www
    RewriteCond %{HTTP_HOST} ^example-new.com$ [NC]
    RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]

    # Removes index.php
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    </IfModule>
    AddType x-httpd-php53 .php

    我似乎在绕圈子,所以我有两个问题可以帮助我写其他重写(尽管可以随意分享建议......):

    1) 要求 3 和 4 的代码是否应该放在“删除 index.php”代码之前?

    2)该职位是否与来自旧网站的重定向有关,例如www.example-old.com/some-link-here.asp 将被重定向到 www.example-new.com/some-new-link-here

    谢谢,

    格雷戈尔

    最佳答案

    1) 从 ExpressionEngine URLs 中删除“index.php”

    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    2) 将“www”添加到所有 URI
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    3) 对以/extranet 开头的任何 URI 强制使用 https://
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^/extranet(.*)$ [NC]
    RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]

    4) 重定向不是/extranet 的 https://URI
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^/extranet(.*)$ [NC]
    RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]

    综上所述,这是您完整的重写规则集:
    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on

    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^/extranet(.*)$ [NC]
    RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]

    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !^/extranet(.*)$ [NC]
    RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]

    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    </IfModule>

    关于.htaccess - htaccess 中的 https 和规则顺序(使用表达式引擎),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8762237/

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