views:

77

answers:

2

so i want to do an external permanant redirect (301) from http://www.creya.com to http://creya.com.

i am not using apache but rather, abyss web server and i can't figure out the url rewrite rules. but i believe i could also do this at the app level with php.

i think wordpress does do this. i set http://creya.com/blog as your blog url and try to hit http://www.creya.com/blog; it redirects to http://creya.com/blog. i want to do the same thing.

any ideas how i can make this hijacking happen?

thanks in advance.

+3  A: 

try

if(substr($_SERVER['SERVER_NAME'],0,4) == 'www.')
    header("Location: http://". substr($_SERVER['SERVER_NAME'], 4)

Long time since I coded php, so can't remember how to get the full path, read a bit here (http://php.net/manual/en/reserved.variables.server.php) and change the last $_SERVER['SERVER_NAME']

Terw
this worked for me, except i had to add REQUEST_URI to get the original$original_url=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']
venksster
+8  A: 

This should do it-

   if($_SERVER['SERVER_NAME']!='creya.com')
    {
        Header("HTTP/1.1 301 Moved Permanently");
        Header("Location: http://creya.com".$_SERVER['REQUEST_URI']); 
    }
andrew