Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mvnobrega's avatar

www does not work at all urls

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?

0 likes
3 replies
Snapey's avatar

I usually do this in my virtual hosts settings on apache

two separate sites with one redirecting to the other

Typically there is nothing in my projects that tie it to a domain name

1 like

Please or to participate in this conversation.