0

sorry i searched but dont find my solution I have a laravel project on my host located in a folder www, in this folder there are all the files of the application and my .htaccess file, I would like that all the links: http://www... are redirected to http://... (without www) because I have problems with google.

Here is the content of my .htaccess file

    RewriteEngine On

        ## www -> no-www
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ 
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE,QSA]
        ## http -> https
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE,QSA]

but it does not work, if I go to my site with both urls, I have no redirection

Samir B
  • 152
  • 1
  • 2
  • 13
  • Possible duplicate of [Generic htaccess redirect www to non-www](https://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) – Travis Britz Aug 01 '19 at 23:04
  • i added this line in my .htaccess : Header always set Strict-Transport-Security "max-age=31536000" ---> its working for http -> https but not for www -> no-www – Samir B Aug 06 '19 at 14:31

1 Answers1

1

Add this rules in top of your .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    # www -> no-www
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule (.*) https://example.com/$1 [R=301,L]
    # http -> https
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://example.com/$1 [R=301,L]

</IfModule>
JarekBaran
  • 1,311
  • 2
  • 7
  • 12