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.

Problem with supported index.php removal method

June 29, 2012 5:25pm

Subscribe [3]
  • #1 / Jun 29, 2012 5:25pm

    Versa Studio

    572 posts

    Hi,

    I’m using this method:

    <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>

    However, I am getting some undesired behavior. For example, the URL:
    http://versastudio.com/l/wisconsin-a
    gets rewritten to
    http://versastudio.com/index.php/l/wisconsin-b

    Ideas?

  • #2 / Jun 29, 2012 8:56pm

    boldyellow

    89 posts

    Just throwing a couple thoughts out here…
    Remove the “index.php” from the “Name of your site’s index page” in Admin > General Configuration.
    Try the add question mark in the .htaccess comment (I once had to do that for one web host).

  • #3 / Jul 03, 2012 11:09am

    Dan Decker

    7338 posts

    Hi Versa Studio,

    As bold yellow points out, have you made sure to remove it from Admin->General Configuration?

    Another option is to double check with your host that .htaccess re-writes are enabled.

    I look forward to your reply!

    Cheers,

  • #4 / Jul 03, 2012 2:12pm

    Versa Studio

    572 posts

    “Name of your site’s index page” is blank.
    Rewrites are enabled, the site is on Engine Hosting.

  • #5 / Jul 03, 2012 2:35pm

    That .htaccess rule you’re using doesn’t have anything to do with a URL redirect; all it does is process a request with index.php if the request isn’t for a file or a directory; see my comments below:

    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] #If not ending in gif, jpg, jpeg, or png
    RewriteCond %{REQUEST_FILENAME} !-f # If not a file
    RewriteCond %{REQUEST_FILENAME} !-d # If not a directory
    RewriteRule ^(.*)$ /index.php/$1 [L] # Process request with index.php

    You want something like this (which also kills the www subdomain, if that’s something you’re interested in):

    # ---------------------------------------------------------------------
    # Enable Rewrite Engine
    # Use RewriteBase to define path to base of EE install, e.g. /development/project-name/, if not in root of domain
    # ---------------------------------------------------------------------
    
    RewriteEngine on
    RewriteBase /
    
    # ---------------------------------------------------------------------
    # Kill www subdomain
    # Example: <a href="http://www.example.com/foo/">http://www.example.com/foo/</a> -> <a href="http://example.com/foo/">http://example.com/foo/</a>
    # Doesn't apply to https URLs
    # ---------------------------------------------------------------------
    
    RewriteCond %{HTTPS} !=on
    RewriteCond %{THE_REQUEST} ^GET [NC]
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    # ---------------------------------------------------------------------
    # In any request contains "index.php"  ...
    # ... and is an Apache GET request ....
    # Then ...
    # ... redirect to the requested location without "index.php"
    # ---------------------------------------------------------------------
    
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] 
    RewriteRule (.*?)index\.php/*(.*) $1$2 [R=301,L]
    
    # ---------------------------------------------------------------------
    # This rule is needed if query string is given to homepage w/o template name in URI, e.g. example.com instead of example.com/default_template_group_name
    # Note: you must may have to change the name of the default template group in this rule to match your setup
    #
    # If any request request that is not at least 1 char long ...
    # ... and contains any sort of query string 1 or more chars in length ...
    # ... and doesn't contain a query string of "css=" or "URL=" or "ACT=" ...
    # Then ...
    # ... process it with /index.php?/[defult template group]/[request]
    # ---------------------------------------------------------------------
    
    RewriteCond %{QUERY_STRING} ^(.+)$
    RewriteCond %{QUERY_STRING} !(css|URL|ACT)=
    RewriteRule !^(.+)$ index.php?/site/$1 [L]
    
    # ---------------------------------------------------------------------
    # This rule is needed to handle query strings in EE
    #
    # If entire any request ...
    # ... doesn't contain an image, css, or js extension, ...
    # ... and isn't a file name ...
    # ... and isn't a directory name ...
    # ... and contains any sort of query string 1 or more chars in length ...
    # Then ...
    # ... process it with /index.php?/[request]
    # ---------------------------------------------------------------------
    
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^(.+)$
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    # ---------------------------------------------------------------------
    # If entire request ...
    # ... doesn't contain an image, css, or js extension, ...
    # ... and isn't a file name ...
    # ... and isn't a directory name ...
    # Then ...
    # ... process it with /index.php/
    # ---------------------------------------------------------------------
    
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

     

  • #6 / Jul 03, 2012 2:45pm

    Versa Studio

    572 posts

    Thanks Nick. I was using NSM HtAccess Generator, but its code interferes with CartThrob. So I went back to the simple, supported method from Ellis Lab.

  • #7 / Jul 04, 2012 5:06pm

    Dan Decker

    7338 posts

    Hi Versa,

    Checking the links in your first post, everything seems to be on the mend here?

    Is there something I’m missing or anything else I can assist you with?

    Cheers,

  • #8 / Jul 05, 2012 2:59pm

    Versa Studio

    572 posts

    Try the first link - it redirects to a different URL, which it should not do.

  • #9 / Jul 06, 2012 10:58am

    Shane Eckert

    7174 posts

    Hey Versa Studio,

    I tried the first link.  http://versastudio.com/l/wisconsin-a points to http://versastudio.com/l/wisconsin-a. There is no index.php for me.

    Is it not working for you?

    Thanks,

  • #10 / Jul 10, 2012 1:14am

    Versa Studio

    572 posts

    Strange - mine is giving me different url titles. In two different browsers.

  • #11 / Jul 11, 2012 12:31pm

    Dan Decker

    7338 posts

    Hi Versa Studio,

    Let’s get in there for a first hand look. Be on the lookout for an email from us!

    Cheers,

  • #12 / Jul 12, 2012 11:34am

    Shane Eckert

    7174 posts

    Hey Versa Studio,

    Can you use the same method here as I gave you for your other case?

    Thanks!

  • #13 / Jul 12, 2012 3:04pm

    Versa Studio

    572 posts

    Info sent.

  • #14 / Jul 12, 2012 3:07pm

    Shane Eckert

    7174 posts

    Hey Versa Studio,

    Awesome!

    Dan will be looking into this.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases