Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

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?
0
Scott Johnston
Asked:
Scott Johnston
  • 10
  • 7
  • 2
  • +1
2 Solutions
 
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 JohnstonSystems ConsultantAuthor 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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
GaryCommented:
You need to add that code to the top of your .htaccess.
0
 
Scott JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor 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 JohnstonSystems ConsultantAuthor Commented:
The normal solutions did not resolve my situation, but were correct in a typical situation....
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 10
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now