Jump to content

Recommended Posts

$domain = $_SERVER['HTTP_HOST'];
$path = $_SERVER['REQUEST_URI'];
if($domain != 'site.com') { header("Location: http://site.com".$path.""); }

 

I am not using this to redirect but there is a functionality in my site when i put www with domain name then it works and it doesn't work when i put the url like http://sitename.com

If you are wanting to modify a URL that is not related to the URL the user is currently viewing (i.e. user entered value), then this will work:

 

preg_replace("/www\./", '', $url);

 

It has one flaw. If the url contains 'www.' anywhere in the url it will be removed. Ex: "subdomainwww.domain.com" would become "subdomaindomain.com". I did that so it would work for values such as "http://www.domain.com". But, I think the likelyhood of such an occurance would be very remote.

 

However, if the values will always start from the subdomain (i.e. not 'http://') then this would be better:

preg_replace("/^www\./", '', $url);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.