2

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:

  1. Remove "index.php" from any url.
  2. 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]

1
  • You should add your answer below, and accept it so this question can be marked as closed. Commented Mar 1, 2013 at 0:11

1 Answer 1

3
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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.