gpt4 book ai didi

apache - 在 htaccess 中将所有页面从非 www 重定向到 www

转载 作者:行者123 更新时间:2023-12-05 04:10:57 26 4
gpt4 key购买 nike

我知道有很多关于从非 www 域到 www 域的重定向的信息。但我的问题是我可以管理主页的重定向,但不能管理子页面。

您可以看到示例 here因此,当我输入 ourenglishclass.eu/fill-in-text-5th-6th-grade 之类的网址时,重定向发生在 www.ourenglishclass.eu/index.php

我可以看到可能有更多的重写规则导致它以这种方式运行,但我找不到是什么,或者我该如何解决这个问题

这些是重定向到/index.php 的规则

 #
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]

我已经尝试了这些从非 www 到 www 的重定向规则:

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

和(这是因为我也在使用 https 进行测试)

  # Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

希望有人能指出出路

最佳答案

问题似乎是由于您将重定向规则置于将所有内容转发到 index.php 的前端 Controller 规则之下,因此使 REQUEST_URI 等于 /index.php.

你的规则是这样的:

RewriteEngine On

# Redirect to www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

#
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule ^ index.php [L]

确保在测试此更改之前清除浏览器缓存。

关于apache - 在 htaccess 中将所有页面从非 www 重定向到 www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43546650/

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