gpt4 book ai didi

.htaccess 重定向删除 php 并重定向到 https 和非 www

转载 作者:行者123 更新时间:2023-12-02 05:19:44 24 4
gpt4 key购买 nike

我的 .htaccess 文件中有以下内容

  • 删除 www
  • 重定向到 https
  • 删除.php

这是我的 .htaccess:

# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

当我在 Firefox 中查看站点时,出现以下错误:

The page isn't redirecting properly. This problem can sometimes be caused by disabling or refusing to accept cookies

Chrome 会警告重定向过多

URL 已更新为我所期望的(删除了 www 并添加了 https)。没有其他有效的重定向

谁能发现我哪里出错了?

最佳答案

看起来您需要在 .htaccess 文件中包含以下内容:

# ----------------------------------------------------------------------
# | Redirect to HTTPS & remove www |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [OR]
RewriteCond %{https} off
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

# ----------------------------------------------------------------------
# | Remove .php extension |
# ----------------------------------------------------------------------
RewriteRule ^(.+)\.php$ /$1 [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ /$1.php [END]

这是从以下类似主题的已接受答案中借用的:

.htaccess - Remove www, force https, remove php and remove trailing slash

关于.htaccess 重定向删除 php 并重定向到 https 和非 www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53206318/

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