簡體   English   中英

Codeigniter .htaccess刪除index.php,但是子目錄訪問如何?

[英]Codeigniter .htaccess to remove index.php but what about sub-directory access?

我有htaccess的成功實現,可以刪除codeigniter中的index.php。 這意味着我可以通過domain.com/controllername訪問任何控制器。

但是,我意識到,使用此實現,我無法通過URL訪問服務器內的子目錄。 如果有解決此問題的可行解決方案,請提出建議。

謝謝

我現在使用的htaccess如下

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|update\.php|administrator\.php|assets|admin|robots\.txt|favicon\.ico)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

<FilesMatch ".(ico|jpg|jpeg|png|gif)$">
ExpiresActive On
ExpiresDefault "access plus 1 month"
</FilesMatch>

標記這可能是您無法訪問系統子文件夾的問題的可能解決方案。

# if a directory or a file exists, use it directly
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php #Here you write the line which will overwrite the index.php and will move the control to your controller.

代碼中的注釋本身就是自言自語。 要獲得更准確的答案,請發布您正在使用的確切方式。 希望對您有幫助。

如果您指出您的域(也稱為子文件夾)內的另一個網站。 像這樣編輯您的.htaccess:

RewriteBase /domain.com/sub-folder/

要么

RewriteBase /sub-folder/

暫無
暫無

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

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