Mark Seah
Mark Seah

Reputation: 542

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. Which meant that I can access any controller via domain.com/controllername.

However, I realized that with this implementation I cannot access sub-directory within the server via the 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

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

Upvotes: 1

Views: 660

Answers (2)

Chand Prakash
Chand Prakash

Reputation: 196

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.

Upvotes: 1

reignsly
reignsly

Reputation: 502

if your pointing out another site inside your domain aka sub-folder. Edit your .htaccess like this :

RewriteBase /domain.com/sub-folder/

or

RewriteBase /sub-folder/

Upvotes: 0

Related Questions