ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Same old topic... removing index.php from URLs

January 24, 2012 7:36pm

Subscribe [1]
  • #1 / Jan 24, 2012 7:36pm

    I’ve tried quite a few different .htaccess files I’ve found while looking for an answer for this for the past couple of hours.

    This works: http://expressionengine.chasin-tails.ca/index.php/pages/reservations

    This doesn’t: http://expressionengine.chasin-tails.ca/pages/reservations

    This doesn’t: http://expressionengine.chasin-tails.ca/reservations

    I’ve verified that I’ve got mod_rewrite loaded via the phpinfo utility.  Fundamentally, I don’t really understand what’s happening the .htaccess file in order to start troubleshooting it.

    Here’s my current file.  It’s located in the public html directory alongside the images, system and themes directories.

    Options +FollowSymLinks
    DirectoryIndex index.php
    
    <IfModule mod_rewrite>
        RewriteEngine On
    
        # Removes index.php
     RewriteCond %{THE_REQUEST} !^POST
     RewriteRule ^site/?(.*)$ /$1 [R=301,L]
    
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ /index.php?/$1 [L]  
    
        # If 404s, "No Input File" or every URL returns the same thing
        # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    I’ve tried it with and without the question mark in the RewriteRule line.

    I would be grateful for any assistance and explanation anyone might be able to provide.  I would love to get to the point where I really understand what’s happening when the Rewrite happens.  Thanks!

  • #2 / Jan 26, 2012 7:54am

    John St-Amand

    865 posts

    Here’s what I use, and so far it’s worked well for me:

    <IfModule mod_rewrite.c>
    
    # Enable Rewrite Engine
    # ------------------------------
    RewriteEngine On
    RewriteBase /
    
    # Redirect www Requests
    # ------------------------------
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    # Redirect index.php Requests
    # ------------------------------
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{THE_REQUEST} !/NAME_OF_YOUR_SYSTEM_FOLDER_HERE/.*
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
    
    # Standard ExpressionEngine Rewrite
    # ------------------------------
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    </IfModule>

    This version removed index.php and also removes www from all incoming requests.  Note that you have to insert your system folder name in the second rewrite condition for the redirect of index.php - this also assumes that your system folder if still below the root - I haven’t yet done this with the system folder above the root.  I didn’t write this - it’s put together based on a couple of different articles on the subject.

    Hope this helps.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases