Redirect from www to non www in laravel using htaccess

You can redirect from www to non www in laravel using htaccess. Htaccess will redirect you from to using RewriteCond %{HTTP_HOST} RewriteRule (.*)$1 [R=301,L] in your htaccess file.

Answers 1
  • Redirect from www to non www using htaccess file in laravel 8

    --PATH .htaccess
    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews -Indexes
        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]
        # Handle Front Controller...
        RewriteCond %{HTTP_HOST}
        RewriteRule (.*)$1 [R=301,L]
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]

    You have to add the below code in your htaccess file

    RewriteCond %{HTTP_HOST}
    RewriteRule (.*)$1 [R=301,L]

    Replace with your domain name in above code. 

    This code snippet is working in my case.

  • Back to code snippet queries related laravel