0

I'm working on a larvel project where everything is fine when I enter the url(domain) without /index.php. Suppose my url is https://example.com. When I go to this url, everything works perfectly. But if I add /index.php at the last like https://example.com/index.php, my resources(images, videos) are not loading because of path mismatch. So far I figure out I need to redirect that https://example.com/index.php to https://example.com by defining rules on .htaccess file.

So how can I write the rules correctly so that it redirects to https://example.com when I enter https://example.com/index.php ?

Update: In development my project is running on http://localhost:3000/Example. In this case I need to redirect this http://localhost:3000/Example/index.php to http://localhost:3000/Example.

Robin
  • 4,902
  • 2
  • 27
  • 43

1 Answers1

3
    RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=301,NC,NE]

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=301,NC,NE]

turn on RewriteEngine and add above lines below RewriteEngine On

  • Your answer supposes to work. But in my case, it redirects me to `http://localhost:3000/dashboard`. I update my question. Would you please see that? – Robin Jul 12 '21 at 10:25
  • isn't it redirecting from (http://localhost:3000/dashboard/index.php) to (http://localhost:3000/dashboard/)? – Sumen Kr Mallick Jul 12 '21 at 10:34