Reputation: 5427
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
.
Upvotes: 0
Views: 1059
Reputation: 81
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
Upvotes: 3