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.

1
  • 1
    refer this Commented Jul 12, 2021 at 10:12

1 Answer 1

2
    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

Sign up to request clarification or add additional context in comments.

2 Comments

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.