0

I know that there are a bunch of answers for this question already on this forum and over the internet. But everything I tried is not working for me and I have no clue why. So that's why I'm asking this question.

I'm running a website with ExpressionEngine CMS. To remove index.php from the URL there is a small .htaccess rule which mentioned below and working fine.

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

Everything running fine with this code in the htaccess file. But now I want to force www. in the URL because some AJAX scripts are not working when the URL is without www.. So I found some threads on this forum:

The last has the most clear solution in my opinion so I added this to my .htaccess file.

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

My .htaccess file now looks like this:

RewriteEngine on

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

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

This however give's me a ERR_TOO_MANY_REDIRECTS error.

I tried all other kind of methods but I keep getting this error and I don't know why. Everything I try to force www. through htaccess doesn't work or gives me this error.

What is going on? Is it possible that DNS settings have to do something with this?

Community
  • 1
  • 1
Timo002
  • 2,845
  • 3
  • 34
  • 55
  • Is there any other code/rule stripping out `www` from URL – anubhava Mar 03 '14 at 17:06
  • Not that I'm aware of! Also if I type www.domain.nl it is (redirected) to domain.nl. There is a DNS CNAME rule for www.domain.nl > domain.nl. can this be it..? – Timo002 Mar 03 '14 at 17:39
  • Yes definitely that is the one since CNAME and rewrite rule are contradicting each other. – anubhava Mar 03 '14 at 17:46
  • I changed the value of this CNAME record value to www.domain.nl. Now wait and see if this is working! – Timo002 Mar 03 '14 at 17:49
  • Is this question answered now? If so perhaps @Timo002 should post his comment as an answer so it can be accepted. – AllInOne Mar 04 '14 at 19:35
  • Well, the htaccess file is working on another server. But in this particular server it's not. Even if I put www. In front of the url, the www. Is always removed from the URL. I changes some DNS settings about 8 hours ago. No result jet... – Timo002 Mar 04 '14 at 20:05
  • Consider turning on the Apache rewrite log and reading the output. Also, could there be something in a Apache .conf file that is causing the behavior, or perhaps another .htaccess file further up the directory hierarchy? – AllInOne Mar 05 '14 at 16:05
  • @AllInOne, Thanks for you support! I'm trying to enable apache rewrite log. However I need to do this in the httpd.conf file and it looks like it's only logging rewrites on the domain where Plesk is running on. The site in question is on the same VPS but different domain. Working on this. Also will check your other suggestions! – Timo002 Mar 06 '14 at 08:55
  • Sorry the details of this are a bit out of my area of expertise. If you get stuck consider opening another question specifically on enabling rewrite log under Plesk. Also be sure to examine all the Apache .conf files for rewrite instructions that might be causing your issue. Usually httpd.conf is for settings that effect all sites and there are other .conf files for things like vhosting or details of particular plug-ins etc. – AllInOne Mar 06 '14 at 16:07
  • DNS by it self DOES NOT redirect, all it does is point the name to an IP. A `CNAME` means it uses a name to then throw it on an IP and `A` is the IP directly. So long the IP leads to the same webserver, it will be either the web server configuration or some other .htaccess within one of the folders. – Prix Mar 09 '14 at 23:14
  • I'm still working on this. Didn't solve it yet and haven't had much time to look at it last week. Didn't find any strang htacces files in the subdirectory. I will keeo looking at this. – Timo002 Mar 09 '14 at 23:16
  • 1
    You need to change it on plesk control panel, you access the domain in question and change the non-www to www or set it to none, on the `subscription > Web Hosting Settings > Preferred Domain` . – Prix Mar 09 '14 at 23:17
  • If I do that I get this error `This DNS record already exists.` – Timo002 Mar 09 '14 at 23:23
  • Do what, change it to none on preferred domain? Well if you have no other `.htaccess` redirecting besides what you have posted above than that is where you will fix your issue. – Prix Mar 09 '14 at 23:28
  • Sorry, I thought you meant to change the domain name. Now I have changed the `Preffered domain` to `www.domain.tld` instead of `domain.tld` and the problem is solved. Thanks! Please write it down as an anwer so I can mark it as an answer! – Timo002 Mar 09 '14 at 23:32

1 Answers1

1

You need to change it on Plesk control panel, you access the domain in question and change the non-www to www or set it to none.

The option you look for is located at subscription > Web Hosting Settings > Preferred Domain.

In case you set it to none then you can use the .htaccess rule.

Prix
  • 18,774
  • 14
  • 65
  • 127