Home > other >  URL redirects to public/public if using www
URL redirects to public/public if using www

Time:02-14

If I go to website.com then my website works correctly.

If I go to www.website.com then I get redirected to www.website.com/public/public which 404s.

If I then go to www.website.com/public it works correctly (but I don't want the added /public)

I want it so that both website.com and www.website.com use the same page. without any publics added/needed in the URL. Here is the .htaccess which is in the root laravel folder (inside public_html)

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

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(.*)$ public/$1 [L]


    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]
    #RewriteBase /laravel/

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

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


</IfModule>
AddType x-httpd-php72 .php

The reason I'm using the rewrite rules are so that I can access assets without using /public e.g /public/css/app.css is /css/app.css

CodePudding user response:

I fixed it. The issue was my env had http://website.com rather than http://www.website.com.

  • Related