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.

Not just another index.php question :)

April 20, 2012 1:46pm

Subscribe [3]
  • #1 / Apr 20, 2012 1:46pm

    JPDesignDev

    20 posts

    I am currently using your recommended solution for removing index.php from the URLs as follows:

    <IfModule mod_rewrite.c>
            RewriteEngine On
    
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            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>

    This works as expected for the most part, and all URLs work perfectly without index.php attached. The issue is that visiting example.com/index.php/products does not “change” the URL automatically to example.com/products. Is there a solution? If it’s not something you can provide insight on, please move to Community Forums.

  • #2 / Apr 23, 2012 10:16am

    Shane Eckert

    7174 posts

    Hello JPDesignDev,

    Thank you for posting your question here on the ExpressionEngine forums.

    That is the expected behavior. I am sure you could force that, but anything else in the .htaccess to make that happen would fall outside of our supported changes to that file.

    That being said, I will move this over to the Community Help Forum as requested. The community there may have some examples to show.

    Cheers,

  • #3 / Apr 25, 2012 7:39am

    John St-Amand

    865 posts

    JPDesignDev, here’s what I use:

    <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} !/system/.*
    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>

    First grouping removes www from all URLs to consolidate traffic to the non-www version of the URL - if that’s not something you want to do you can remove that block.

    Note that with the redirect of index.php, you would need to add your system folder name to the second line so that it’s NOT removed when accessing the CP and only removed from the front end.

    Hope this helps you.  It took me a while to get a handle on what i wanted to do with it.  This is cobbled together from a couple different sources who are much more htaccess literate than I am.

  • #4 / May 01, 2012 4:13pm

    JPDesignDev

    20 posts

    Somehow, I wasn’t subscribed to updates. Thanks for your answers, I will try it out, John!

  • #5 / May 01, 2012 4:15pm

    John St-Amand

    865 posts

    No worries - hope it helps.

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

ExpressionEngine News!

#eecms, #events, #releases