How do i setup a global redirect for my website?

If anyone types in the url "www.name.com" my webiste will work, can I setup a redirect in case someone try's to access our webiste using the wrong info?
IE example, instead of www they type name.com or they type name.name.com,

can it do this with a script, I currently am setting up a test web site and every time I try to access the test.name.com I get redirected.  I checked the .HTACCESS file and I do not think it being done in the /HTACCESS file?  
How else might this be done?
Scott JohnstonIT Manager Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
In your .htaccess you need

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

Open in new window

0
Scott JohnstonIT Manager Author Commented:
Yes, I checked here first and did not find any coding related to this.  Is there other ways to accomplish this task using ?
0
alatham23Commented:
In your Host Records of your DNS configuration for that domain, it must be setup for the "@" to point directly to the same IP address or DNS name as the "www" then anything that is mistyped will be directed to the same as the "www" website.  The @ value needs to be changed to redirect all other things going to it without the "www" on the end.  The * value in the Host Records is the wildcard to catch the "name.name.com" and all others and put them where you want them.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

GaryCommented:
You need to add that code to the top of your .htaccess.
0
Scott JohnstonIT Manager Author Commented:
What I have done recently is cloned my web site so i can play and test new changes without making them in our live site.  Every time I try to access the Test.name.com, it will redirect the site.  I checking on the DNS, I do have it setup that way....I update once I have tested...
0
Scott JohnstonIT Manager Author Commented:
I have check DNS and i have the @ and the * configured, they both send me to the IP address for the website? they are using the sasme IP address as the WWW entry,
 I now have a sub domain called test, I not sure what I need to do in DNS?
0
alatham23Commented:
If the IP address is the same, then you need to add in that subdomain on your web host as well.  If your web host doesn't see the subdomain of "test.name.com" then it won't know where to redirect it.  Your registrar appears to be setup correctly and now you just need to add in the subdomain on the website hosting side.
0
Scott JohnstonIT Manager Author Commented:
I have the sub domain setup, for some reason my old developer built in something that will redirect the site...I cannot find it.  That is why I asked to see if they are other way to get the redirect done, beside the .HTACCESS
0
Jorge OcampoCommented:
Who is your web provider?
0
alatham23Commented:
You need to talk to whomever is hosting that website.  They have to set it up on that end now.
0
Scott JohnstonIT Manager Author Commented:
I did and they stated the we have some kind of coding that is redirecting our page....some kind of PHP script or html?  I am just having problem locating it...
0
Scott JohnstonIT Manager Author Commented:
Here is my htaccess...
.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
0
alatham23Commented:
We had some weird code inside of our index.php file one time that was doing some weird redirecting.  That should be something you can find and remove if you open it up in a text editor.
0
Scott JohnstonIT Manager Author Commented:
I agree, I have renamed the index.php and it then re-directs me to the apache default home page.

Now I got to figure out the coding in the index.php?
0
alatham23Commented:
Yes, there is coding perhaps at the beginning that is doing the redirecting.  I would have a coder on here take a look at the code once you find it or you could just remove it (after making a backup copy) and test it out otherwise.
0
Scott JohnstonIT Manager Author Commented:
Could code like this redirect :

if(strtolower($_SERVER['SERVER_NAME']) == "www.namexxx.com" || strtolower($_SERVER['SERVER_NAME']) == "namexxx.com" || strtolower($_SERVER['SERVER_NAME']) == "name.eu" || strtolower($_SERVER['SERVER_NAME']) == "www.name.eu") {
    //print $_SERVER['SERVER_NAME'];
    @header("HTTP/1.1 301 Moved Permanently");
    @header("Location: http://www.name.com".$_SERVER['REQUEST_URI']);
    exit(0);
} //end if
if($_SERVER['SERVER_NAME'] != "store" && $_SERVER['SERVER_NAME'] != "localstore" && $_SERVER['SERVER_NAME'] != "www.name.com") {
     if(!stristr($_SERVER["SERVER_NAME"],"www")) {
        @header("HTTP/1.1 301 Moved Permanently");
        @header("Location: http://www.name.com".$_SERVER['REQUEST_URI']);
        exit(0);
0
alatham23Commented:
Yes, that could.  The simplest way to find out is the remove that whole block of code from starting bracket { to ending bracket } but make sure you have a backup of that file first.  Then test it live on your host farm.
0
Scott JohnstonIT Manager Author Commented:
When I remove the code the website will just display the default apache web page?
0
alatham23Commented:
I am not much of a programmer myself.  I hope we can get a PHP programmer in this question to help you finalize the last parts of the question.
0
Scott JohnstonIT Manager Author Commented:
The normal solutions did not resolve my situation, but were correct in a typical situation....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.