简体   繁体   English

Codeigniter .htaccess删除index.php,但是子目录访问如何?

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

I have a successful implementation of htaccess to remove index.php in codeigniter. 我有htaccess的成功实现,可以删除codeigniter中的index.php。 Which meant that I can access any controller via domain.com/controllername. 这意味着我可以通过domain.com/controllername访问任何控制器。

However, I realized that with this implementation I cannot access sub-directory within the server via the URL. 但是,我意识到,使用此实现,我无法通过URL访问服务器内的子目录。 Please advice if there is a working solution to resolve such issue. 如果有解决此问题的可行解决方案,请提出建议。

Thank you 谢谢

The htaccess which I am using now is as follows 我现在使用的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>

Mark this may be the probable solution to your issue where you are unable to access the sub folders of the system. 标记这可能是您无法访问系统子文件夹的问题的可能解决方案。

# 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.

The comments in the code are itself self speaking. 代码中的注释本身就是自言自语。 For more exact answer post your exact htacess you are using. 要获得更准确的答案,请发布您正在使用的确切方式。 Hope that helps you. 希望对您有帮助。

if your pointing out another site inside your domain aka sub-folder. 如果您指出您的域(也称为子文件夹)内的另一个网站。 Edit your .htaccess like this : 像这样编辑您的.htaccess:

RewriteBase /domain.com/sub-folder/

or 要么

RewriteBase /sub-folder/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM