簡體   English   中英

將所有文件重定向到index.php

[英]redirect all files to index.php

我嘗試將所有文​​件和文件夾重定向到index.php進行MVC路由,但是它只能從index.phplearn.delapiata.ro/index.php/i/can/put/anything/here/and/redirect

我希望在沒有index.php情況下工作: learn.delapiata.ro/controllers/any_php_file.php

我在.htaccess使用此:

   RewriteEngine On
   RewriteBase /
   RewriteRule ^index.php$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule  ^(.*)$ /index.php [L]

謝謝。

您所擁有的已經可以工作-但您只需要-f規則:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule  ^ index.php [L]

這些規則僅表示:如果請求未指向存在的文件,則將requeset發送到index.php

需要注意的是,如果他們是在Apache的配置啟用htaccess的文件只能在所有生效。 例如,如果將htaccess文件修改為包含錯誤(在其中輸入“ asdf”),而您沒有得到500的響應,則Apache無法讀取.htaccess文件,這就是為什么它“不起作用”的原因”。 要解決此問題,請將AllowOverride All放在apache配置文件中的適當位置,然后重新啟動apache。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM