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.

Unable to remove index.php and www via htaccess

November 17, 2012 3:09pm

Subscribe [2]
  • #1 / Nov 17, 2012 3:09pm

    jezpeters

    6 posts

    My site is set up to not use the www.

    Using the code in the documentation to remove the index.php works fine.

    However, when I add the necessary rules to redirect the www to non-www and then go to a URL with the www in it, the index.php is always added.

    So, http://mysite/blog works and the index.php is removed, but if I go to http://www.mysite/blog I am redirected to http://mysite/index.php/blog.

    Here are the rules I am using:

    <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)
       
            # Trying to remove www
            RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
            RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
      
    </IfModule>

    The www rewrite portion was taken from the HTML5 boilerplate.

    Any pointers would be greatly appreciated, thanks.

     

  • #2 / Nov 19, 2012 3:19pm

    Shane Eckert

    7174 posts

    Hello jezpeters,

    Thank you for asking your question.

    We do not support the removal of www, but I would like to see if we can get this to work.

    One thing to make sure of is that in the Control Panel and in the config.php that you are consistent with the use or non-use of WWW.

    It would also be helpful to see the Apache logs, wondering if anything comes through when this is going on.

    Cheers,

  • #3 / Nov 19, 2012 5:10pm

    jezpeters

    6 posts

    Hi Shane, thanks for the reply.

    All the URL’s in the control panel are non-www, and the one in the config.php is also non-www. I’ve had a look at the logs, and there is nothing related to the site, just some 404’s related to some other sites of mine.


    Jez

  • #4 / Nov 19, 2012 5:21pm

    MadWebDesigns

    147 posts

    Hi jezpeters,

    Try re-ordering your htaccess rules like so:

    <IfModule mod_rewrite.c>
    
            RewriteEngine On
    
            # Trying to remove www
            RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
            RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
    
            # 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>

    Mike

  • #5 / Nov 19, 2012 5:37pm

    jezpeters

    6 posts

    That’s sorted it, brilliant - thanks very much Mike.

  • #6 / Nov 19, 2012 5:39pm

    MadWebDesigns

    147 posts

    Any time :D

  • #7 / Nov 20, 2012 10:45am

    Shane Eckert

    7174 posts

    Hey there jezpeters,

    I am glad that Mike was able to help! Thanks Mike.

    That’s a good one to note.

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases