Redirect without https and non www to https: // www with wildcard support

I can achieve the following things.

https://domain.com -> https://www.domain.com
http://www.domain.com -> https://www.domain.com
http://domain.com -> https://www.domain.com

      

Everything works fine ... But also, I need the wildcard to work, for example

https://domain.com/randomblabla.html -> https://www.domain.com/randomblabla.html

      

where randomblabla.html doesn't exist ... it just shows the content of index.php ... before I set up the https redirect it worked fine ... but now its redirect tohttps://www.domain.com/index.php

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)(\/?)$ index.php [QSA,NC,L]



RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

# Remove Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L,NE]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

      

+3


source to share


1 answer


The problem is the excessive presence of a front controller, such as a rule on top. Try this code:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]

# Remove Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L,NE]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

      



Make sure to test your new browser to avoid the old 301 caches.

0


source







All Articles