Solved

How do i setup a global redirect for my website?

Posted on 2014-07-22
20
355 Views
Last Modified: 2014-07-29
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?
0
Comment
Question by:Scott Johnston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 2
  • +1
20 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 40212152
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
 

Author Comment

by:Scott Johnston
ID: 40212168
Yes, I checked here first and did not find any coding related to this.  Is there other ways to accomplish this task using ?
0
 

Accepted Solution

by:
alatham23 earned 250 total points
ID: 40212172
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

Expert Comment

by:Gary
ID: 40212188
You need to add that code to the top of your .htaccess.
0
 

Author Comment

by:Scott Johnston
ID: 40212239
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
 

Author Comment

by:Scott Johnston
ID: 40212253
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
 

Expert Comment

by:alatham23
ID: 40212273
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
 

Author Comment

by:Scott Johnston
ID: 40212316
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
 
LVL 2

Expert Comment

by:Jorge Ocampo
ID: 40212332
Who is your web provider?
0
 

Expert Comment

by:alatham23
ID: 40212384
You need to talk to whomever is hosting that website.  They have to set it up on that end now.
0
 

Author Comment

by:Scott Johnston
ID: 40212414
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
 

Author Comment

by:Scott Johnston
ID: 40212482
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
 

Expert Comment

by:alatham23
ID: 40212499
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
 

Author Comment

by:Scott Johnston
ID: 40212527
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
 

Expert Comment

by:alatham23
ID: 40212541
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
 

Author Comment

by:Scott Johnston
ID: 40212656
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
 

Expert Comment

by:alatham23
ID: 40212689
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
 

Author Comment

by:Scott Johnston
ID: 40212851
When I remove the code the website will just display the default apache web page?
0
 

Expert Comment

by:alatham23
ID: 40213907
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
 

Author Closing Comment

by:Scott Johnston
ID: 40227078
The normal solutions did not resolve my situation, but were correct in a typical situation....
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question