Reputation: 31
Recently, I enforced non-www to www redirection on my website.
I am using these rules in my htaccess file:
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
It works well except that people coming form this link structure:
https://example.com/blog/9999/titlequerystring
get redirected that way by the server:
https://example.com/blog/9999/titlequerystring
then--
https://example.com/blog.php/9999/titlequerystring
then--
https://www.example.com/blog.php/9999/titlequerystring
The .php after "blog" brings users to error page no found.
It should redirect like that to work properly:
https://www.example.com/blog/9999/titlequerystring
This is a custom CMS. Not Wordpress. It uses Multiviews to work properly. My server is set with Apache 2.4+PHP 7.4 and PHP-FPM as handler.
I've been trying to fix this for a few days but I guess I am not skilled enough to diagnose it further.
Thanks.
As replied to CBroe, here is the htaccess file for mod_rewrite without Multiviews:
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
Upvotes: 1
Views: 71