81 responses to “CodeIgniter htaccess”

  1. Sachin Sharma

    I have a HTML website with an issue:

    Google Webmaster Tool shows duplicate pages:

    http://www.domain.com/folder/
    http://www.domain.com/folder/index.html

    I want only http://www.domain.com/folder/index.html to be visible and accessible. How can this be done with .htaccess ?

  2. rot

    REDIRECTING OLD DYNAMIC URLS :

    Here’s a really usefull tip when you need to redirect old dynamic urls to new ones, specialy when there are GET vars in old urls (codeigniter refuse GET vars when using default config, and a simple Redirect 301 will fail)

    Here’s the solution :
    1. sample old url : page.php?id=1234&lang=en
    2. sample new url : newpage/action/1234#contact

    .htaccess :
    RewriteCond %{REQUEST_URI} ^/page\.php$ [NC]
    RewriteCond %{QUERY_STRING} id=([0-9]+)&lang=en$ [NC]
    RewriteRule ^(.*)$ en/newpage/action/%1#contact? [NE,R=301,L]

    Note that [NE] will allow to include an anchor in the destination url and the last caracter “?” will prevent query string to interfere with in the dest url.

    Hope it’ll save someone’s time !

    ——————-

    @SACHIN:
    RewriteRule ^folder/?$ folder/index.html [R=301,L]

    should do the trick

  3. rot

    @sachin: you might replace [R=301,L] with [L]

  4. Mark LaDoux

    I’ve got an improvement, reflecting current Apache rules –

    change

    # If your default controller is something other than
    # “welcome” you should probably change this
    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    to read as

    ### Remove index.php from URL
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/[^\s\?]+)? [NC]
    RewriteRule ^ %1 [L,R=301]

    # If your default controller is something other than
    # “welcome” you should probably change this
    RewriteRule ^(welcome(/index)?)/?$ / [L,R=301]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    This way, the index.php gets removed whenever it’s included in the URL, your current rules only remove it when it’s mentioned after /start/ which should produce a 404 error, and therefore defeating the purpose.

    My method will remove it whenever it’s called after whatever RewriteBase is set to.

  5. ano

    By reversing the following line :
    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]

    to something like :
    RewriteRule ^/?$ /index.php [L,R=301]

    Note: in “/index.php” you might remove the slash :unsure:

  6. hey

    Hello,

    Where should we put this .htaccess file(right next to index.php in the application folder ?)

    Same question for those using codeigniter HMVC.

    Thank you.