You could try: https://stackoverflow.com/questions/50381162/laravel-force-www-and-https-error-redirect-to-index-php
Edit: Just curious, why the need for www?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to ensure that all routes are https://www
https already works on all, but only the home page redirects to www
I've tried all kinds of code on the internet and it doesn't work.
The laravel public folder is inside public_html and the laravel files are inside the "laravel" folder at the same level as public_html.
So in the htaccess of public_html I have this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# Redirect to WWW
RewriteCond %{HTTP_HOST} !^www\.meempi\.com
RewriteRule (.*) http://www.meempi.com/ [L,R=301]
And "Laravel folder":
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ /../public_html/public/ [L]
# php -- BEGIN cPanel-generated handler, do not edit
# Defina o pacote “ea-php73” como a linguagem padrão de programação “PHP”.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
As I understand it, the following code should force www on all routes:
RewriteCond %{HTTP_HOST} !^www\.meempi\.com
RewriteRule (.*) http://www.meempi.com/ [L,R=301]
But it only works on the homepage, all other routes can be accessed as https://site.com
It already includes the same code in the .htaccess of the laravel folder, but it has no effect.
Can anyone help me solve this?
You could try: https://stackoverflow.com/questions/50381162/laravel-force-www-and-https-error-redirect-to-index-php
Edit: Just curious, why the need for www?
Please or to participate in this conversation.