I have just launched a Laravel 5.3 project on a live server and all is going well except one.

But my issue is, my websites are running on all 3 different URLs:

  1. example.com

  2. example.com/public/index.php

  3. example.com/<any-word>/index.php

My .htaccess is: (This file is in the root folder)

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    RewriteRule ^(.*)$ public/index.php$1 [L]

But I just want to see my website with example.com URL only.


You would need to issue an external redirect before your existing directives. For example, immediately after the RewriteEngine directive, try something like:

RewriteCond %{REDIRECT_STATUS} ^$
RewriteRule ^[^/]+/index\.php(.*) /$1 [R=301,L]

Make sure you clear your browser cache when testing.

The RewriteCond directive, checking against REDIRECT_STATUS, prevents a redirect loop after the internal rewrite at the end.

  • Hi, Thank you for help me, but this code not work for me :-(
    – mySun
    Mar 2 '17 at 20:01
  • Don't load any CSS and JS file !
    – mySun
    Mar 2 '17 at 20:20
  • I've just corrected the regex in the above RewriteRule. However, as it was, it shouldn't have done anything?! Can you confirm that your site is functioning correctly without this directive when you access example.com/? Missing CSS and JS files are a client-side relative URL problem, see also my answer to this other question: webmasters.stackexchange.com/a/86458/1243
    – MrWhite
    Mar 2 '17 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.