Solved

How do i setup a global redirect for my website?

Posted on 2014-07-22
20
337 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
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
Several part series to implement Internet Explorer 11 Enterprise Mode
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now