.htaccess Redirect

Hi All,

Currently our site is allowing visitors to navigate to the home page using several url paths. I’ve contacted my hosting provider to get some suggestions on redirecting our site to www.example.com. They gave me a link to a forum post where there was the provided code below. I have a couple questions on creating a .htaccess file:

1 - Will the code below redirect all traffic to my home page to www.example.com (exactly)? Redirecting example.com and Example Domain?

2 - I will use the TextEdit.app to save a plain text file encoding using Unicode (UTF-8). Any issues with this?

3 - Is there any other code I need in the document to make it function properly as a .htaccess file?

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

Thank you for your help,

TeamSDA_Christian


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I just did this yesterday for the same reasons as you. I got the code from my hosting service. It’s a little different from what you have:

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

But that doesn’t mean you should use this without finding out for sure. I think I read that the code can be different for Apache servers and others. (If not, someone will let us know.)

After I got the file on the server, everything worked perfectly and all the other possibilities resolved to www.example.com

I found an easy way to get it on the server. In my control panel there’s a file management icon, of course. And in there I’m able to create a file right on the server, so I didn’t have to worry about using a text editor and uploading the file.

HTH
Martin

On Mar 18, 2011, at 8:22 PM, TeamSDA wrote:

Hi All,

Currently our site is allowing visitors to navigate to the home page using several url paths. I’ve contacted my hosting provider to get some suggestions on redirecting our site to www.example.com. They gave me a link to a forum post where there was the provided code below. I have a couple questions on creating a .htaccess file:

1 - Will the code below redirect all traffic to my home page to www.example.com (exactly)? Redirecting example.com and Example Domain?

2 - I will use the TextEdit.app to save a plain text file encoding using Unicode (UTF-8). Any issues with this?

3 - Is there any other code I need in the document to make it function properly as a .htaccess file?

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

Thank you for your help,

TeamSDA_Christian


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Martin,

Christian is out today but I want to get back to you to thank you for your input. We will be reviewing this issue tomorrow and your suggestions are helpful.

Team SDA_Dave


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi All,

First, thank you Martin for your input. My hosting company told me they don’t get involved in writing code directly for customers and gave me a link to a forum post talking about setting up an .htaccess file on the Apache server, thats where I found my code. Is there someone that can recommend the proper configuration for my .htaccess file for our Apache servers.

Thank you,

TeamSDA_Christian


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

http://httpd.apache.org/docs/2.2/howto/htaccess.html

The definitive guide.

Walter

On Mar 22, 2011, at 7:01 PM, TeamSDA wrote:

Hi All,

First, thank you Martin for your input. My hosting company told me
they don’t get involved in writing code directly for customers and
gave me a link to a forum post talking about setting up an .htaccess
file on the Apache server, thats where I found my code. Is there
someone that can recommend the proper configuration for my .htaccess
file for our Apache servers.

Thank you,

TeamSDA_Christian


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thank you Walter for the link. Looking through apache.org and a other couple forums, I’ve put together the code that is listed below for my .htaccess file. Since I’m just a beginner at putting together an .htaccess file, can anyone see any issues with the code? I’ve listed the functions of this code below.

  1. Redirects non-www. to www.

  2. Redirects Example Domain to the root (www.example.com)

  3. Take all 404 Errors to the custom error page

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]/)index.html(?[^ ])? HTTP/
RewriteRule ^(([^/]
/)*)index.html$ http://www.example.com/$1 [R=301,L]

ErrorDocument 404 /Errors/404.html

Thank you for your help,

TeamSDA_Christian


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options