hello world
hello world

Reputation: 1755

non www to www redirect htaccess on laravel

im doing some very simple stuff with my .htaccess file located in my public directory

here is my .htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # domain.com redirect to www.domain.com
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

very standard striaght out of the box stuff. but whenever i type domain.com in the browser it jsut redirects to a yahoo dns search

Upvotes: 1

Views: 1929

Answers (1)

samrap
samrap

Reputation: 5673

Try this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301,NC]

You want to redirect everything at domain.com to www.domain.com

Upvotes: 1

Related Questions