venksster
venksster

Reputation: 73

how do i strip out the WWW in my url using php

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.

Upvotes: 0

Views: 246

Answers (2)

Andrew Hopper
Andrew Hopper

Reputation: 966

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']); 
    }

Upvotes: 8

ThoKra
ThoKra

Reputation: 3029

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']

Upvotes: 3

Related Questions