1

最近,我在我的网站上强制执行非 www 到 www 重定向。

我在我的 htaccess 文件中使用这些规则:

Options -Indexes
Options +FollowSymLinks

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault A1209600
  ExpiresByType text/html A1
</IfModule>

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php

它运作良好,除了人们来自这个链接结构:

https://example.com/blog/9999/titlequerystring

被服务器以这种方式重定向:

https://example.com/blog/9999/titlequerystring

然后 -

https://example.com/blog.php/9999/titlequerystring

然后 -

https://www.example.com/blog.php/9999/titlequerystring

“博客”之后的 .php 将用户带到错误页面未找到。

它应该像这样重定向才能正常工作:

https://www.example.com/blog/9999/titlequerystring

这是一个自定义 CMS。不是WordPress。它使用多视图正常工作。我的服务器设置为 Apache 2.4+PHP 7.4 和 PHP-FPM 作为处理程序。

几天来我一直在尝试解决此问题,但我想我的技能不足以进一步诊断它。

谢谢。

正如 CBroe 的回复,这里是不带 Multiviews 的 mod_rewrite 的 htaccess 文件:

Options -Indexes
Options +FollowSymLinks

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault A1209600
  ExpiresByType text/html A1
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* loader.php [L,QSA]
</IfModule>

ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php

loader.php: https ://controlc.com/47512763

4

0 回答 0