OVH Community, your new community space.

Issue with redirection and .htaccess


cartwright118
21-06-2014, 17:26
Quote Originally Posted by louis_gregre
Hi Christian,

I forgot to delete the .htaccess that was in the root folder before adding the .htaccess in the www folder...

Everything is working now... Thank you for your help!

All the best,

Louis
No problem. Sorry it wasn't so straight forward.... .htaccess can be very simple, but complicated too. Without having access to the server it is sometimes quite difficult to try and diagnose Glad you got it sorted anyway!

Christian

louis_gregre
21-06-2014, 13:48
Quote Originally Posted by cartwright118
If you delete the .htaccess file you just created and browse to domain.com what happens?
I assume you only have 1 .htaccess file? And are using the one I gave you? - This definitely works, I tried it myself.
You need to check to see if you have any other .htaccess files in the upper levels of the folder structures in the public webroot
What are you using to host your website? - A panel? (cPanel/Plesk/etc)
What is your domain name?
What is your website location on the server?


If you don't want to give the details on the forum, then PM them to me.

Christian

Hi Christian,

I forgot to delete the .htaccess that was in the root folder before adding the .htaccess in the www folder...

Everything is working now... Thank you for your help!

All the best,

Louis

cartwright118
20-06-2014, 00:13
Quote Originally Posted by louis_gregre
Hi Christian,

I added the code in a new .htaccess within the www folder but the same error appears: when I go to mydomain.com it redirects to www.mydomain.com/www/?

I really don't know why this keeps happening?

Thanks in advance for your help.

Louis
If you delete the .htaccess file you just created and browse to domain.com what happens?
I assume you only have 1 .htaccess file? And are using the one I gave you? - This definitely works, I tried it myself.
You need to check to see if you have any other .htaccess files in the upper levels of the folder structures in the public webroot
What are you using to host your website? - A panel? (cPanel/Plesk/etc)
What is your domain name?
What is your website location on the server?


If you don't want to give the details on the forum, then PM them to me.

Christian

louis_gregre
19-06-2014, 14:48
Quote Originally Posted by cartwright118
It won't redirect it in the browser bar. It will still show domain.com or www.domain.com depending on which one you use. The website will just load either your visitor uses. If you WANT it to redirect to WWW. then use .htacess file as explained above. Make sure it's in your public html directory though and not root. Either way you should add that CNAME record or the A record approach, both will work.

Christian
Hi Christian,

I added the code in a new .htaccess within the www folder but the same error appears: when I go to mydomain.com it redirects to www.mydomain.com/www/?

I really don't know why this keeps happening?

Thanks in advance for your help.

Louis

cartwright118
18-06-2014, 19:46
Quote Originally Posted by louis_gregre
Hi,

Thank you for your answer.

Currently I have an A record for domain.com going to 123.45.45.45 and an A record for www.domain.com going to the same address.

Should I delete the second A record and replace it with a CNAME pointing to domain.com?

Will it automatically redirect domain.com to www.domain.com?

All the best,

Louis
It won't redirect it in the browser bar. It will still show domain.com or www.domain.com depending on which one you use. The website will just load either your visitor uses. If you WANT it to redirect to WWW. then use .htacess file as explained above. Make sure it's in your public html directory though and not root. Either way you should add that CNAME record or the A record approach, both will work.

Christian

louis_gregre
18-06-2014, 18:04
Quote Originally Posted by cartwright118
Put the .htaccess in your public HTML folder (WWW)

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

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

You can achieve what you are trying to do much easier by using a CNAME record on your DNS.
If you create an A record for domain.com > 123.45.45.45
Then a cname for www.domain.com > domain.com
Hi,

Thank you for your answer.

Currently I have an A record for domain.com going to 123.45.45.45 and an A record for www.domain.com going to the same address.

Should I delete the second A record and replace it with a CNAME pointing to domain.com?

Will it automatically redirect domain.com to www.domain.com?

All the best,

Louis

cartwright118
18-06-2014, 14:26
Quote Originally Posted by louis_gregre
Hi,

I'm trying to redirect mydomain.com to www.mydomain.com using the .htaccess file.

The code I added is:

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

The .htaccess file is in the rootfolder, not in the "www" folder.

The following error occurs when I try to go to mydomain.com. It's trying to load the URL "http://www..mydomain.com/www/" instead of "http://www..mydomain.com".

Can somebody help please?

Thanks,

Louis
Put the .htaccess in your public HTML folder (WWW)

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

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

You can achieve what you are trying to do much easier by using a CNAME record on your DNS.
If you create an A record for domain.com > 123.45.45.45
Then a cname for www.domain.com > domain.com

louis_gregre
18-06-2014, 09:52
Hi,

I'm trying to redirect mydomain.com to www.mydomain.com using the .htaccess file.

The code I added is:

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

The .htaccess file is in the rootfolder, not in the "www" folder.

The following error occurs when I try to go to mydomain.com. It's trying to load the URL "http://www..mydomain.com/www/" instead of "http://www..mydomain.com".

Can somebody help please?

Thanks,

Louis