[英]PHP-Laravel redirect to root(/) from /index.php
I'm working on a larvel project where everything is fine when I enter the url(domain) without /index.php
.我正在开发一个 larvel 项目,当我输入没有/index.php
的 url(domain) 时,一切都很好。 Suppose my url is https://example.com
.假设我的网址是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.但是如果我在最后添加/index.php
像https://example.com/index.php
,我的资源(图像,视频)由于路径不匹配而无法加载。 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.到目前为止,我发现我需要通过在.htaccess
文件上定义规则来将https://example.com/index.php
重定向到https://example.com
。
So how can I write the rules correctly so that it redirects to https://example.com
when I enter https://example.com/index.php
?所以,我怎么能写的规则正确,以便它重定向到https://example.com
当我输入https://example.com/index.php
?
Update: In development my project is running on http://localhost:3000/Example
.更新:在开发中,我的项目在http://localhost:3000/Example
。 In this case I need to redirect this http://localhost:3000/Example/index.php
to http://localhost:3000/Example
.在这种情况下,我需要将此http://localhost:3000/Example/index.php
重定向到http://localhost:3000/Example
。
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打开 RewriteEngine 并在 RewriteEngine On 下面添加上面的行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.