1

Has anyone had any luck combining the new .htaccess rules for removing index.php with a rule to add (or remove) the www string? Previously, we would use the following:

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule (.*) http://www.example.com/$1 [L,R=301]

   # Removes index.php
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

However the new suggested code:

    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

...is throwing all kinds of errors for me when combined with the www rule set:

    RewriteCond %{HTTP_HOST} ^example\.com$
    RewriteRule (.*) http://www.example.com/$1 [L,R=301]

1 Answer 1

1

I'm using this code:

# ----------------------------------------------------------------------

# Option 1:
# Rewrite "www.domain.com -> domain.com" 


  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


# 

I ever used the Ellislab suggested code to remove index.php, it doesn't work fine on the Apache server where Expression Engine is installed. Using the addon htaccess Maker it's working fine, nice performance: http://devot-ee.com/add-ons/htaccess-maker

3
  • This .htaccess is on the server root, to remove the index.php is in my site root.
    – Stéphane
    Mar 6, 2014 at 0:03
  • Thanks Stéphane. For what it's worth, our typical code block above still works well. I was hoping to build it using the new recommended code block so we fully remove the index.php (ellislab.com/blog/entry/fully-removing-index.php-from-urls). Mar 6, 2014 at 7:03
  • The problem is each Apache server could have different parameters so the .htaccess indicated from Ellislab was not working where my site is hosted. I tried many configurations, only the addon htaccess-maker works fine in my case. Nice your typical code block still works well :)
    – Stéphane
    Mar 6, 2014 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.