I have a CodeIgniter project placed in a subfolder of a domain. I want to have my .htaccess (placed in the CodeIgniter subfolder) to do the following, for any url involving the CodeIgniter directory:
- Remove "index.php" from any url.
- Always add a trailing slash to any url.
Currently my .htaccess look like this:
RewriteEngine on
RewriteBase /ci_folder/ #This is the CI Subfolder
# Get rid of index.php
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
# Add trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
The problem is, that its only working partially; The index.php is removed fine, but when adding the trailing slash, instead of redirecting to a "fixed" url, its redirecting to the local path, fx.
domain.com/ci_folder/method
is redirected to:
domain.com/home/sites/domain.com/public_html/ci_folder/index.php/method/
which should have been : domain.com/ci_folder/method/ instead! (and also not include any index.php)
--- EDIT ---
This did it for me:
RewriteEngine on
RewriteBase /ci_folder/
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
RewriteCond %{REQUEST_URI} !(.*)/$
# dont rewrite if there was posted here!
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]