2

We are running an EE site which is successfully stripping the /index.php from the URL using the following rewrite rule:

RewriteCond $1 !^(docs|index.php|sitemap.php) [NC] RewriteRule ^(.*)$ /index.php/$1 [L]

I now need to get the site to redirect from the non www (example.com) version to the www. (www.example.com) version of the site. At the moment I've tried:

RewriteCond $1 !^(docs|index\.php|sitemap\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]

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

This adds the 'www.', but puts the index.php back on all pages of the site. What am I doing wrong?

1
  • How does your htaccess file look like? I'm useing this at the moment RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L] And this strips www. of the URL. But I want to add www. Using your code causes redirections
    – Timo002
    Jan 23, 2014 at 11:35

2 Answers 2

7

Try changing the order of your RewriteRules. i. e. put the addition of the www before the removal of the index.php.

0
2

This is the .htaccess we use for clients who request the www.:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
1
  • Using your code causes in my setup ERR_TOO_MANY_REDIRECTS. Don't understand why...
    – Timo002
    Jan 23, 2014 at 11:27

Your Answer

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

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