[英]PHP-Laravel redirect to root(/) from /index.php
我正在開發一個 larvel 項目,當我輸入沒有/index.php
的 url(domain) 時,一切都很好。 假設我的網址是https://example.com
。 當我轉到此網址時,一切正常。 但是如果我在最后添加/index.php
像https://example.com/index.php
,我的資源(圖像,視頻)由於路徑不匹配而無法加載。 到目前為止,我發現我需要通過在.htaccess
文件上定義規則來將https://example.com/index.php
重定向到https://example.com
。
所以,我怎么能寫的規則正確,以便它重定向到https://example.com
當我輸入https://example.com/index.php
?
更新:在開發中,我的項目在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]
打開 RewriteEngine 並在 RewriteEngine On 下面添加上面的行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.