Jump to content

changing a web address using PHP


LucyEleanor

Recommended Posts

Hi, I have a second website under the same domain www.lucyeleanorbrown.com/weddings.html which I wanted to change to www.weddings.lucyeleanorbrown.com, I have been looking around for PHP for this but am unsure of what to search for, could anyone give me a suggestion?

Thank you

Link to comment
https://forums.phpfreaks.com/topic/222122-changing-a-web-address-using-php/
Share on other sites

Hi,And So this is from http://answers.yahoo.com/question/index?qid=20081022233752AAelpQP:)

There is a global variable in PHP that holds the current domain name.

 

$_SERVER[ 'HTTP_HOST' ];

 

Here's an example using strpos that prints a different h1 tag depending on which domain is typed in the browser.

 

if( strpos( $_SERVER[ 'HTTP_HOST' ], "xxxx.com" ) !== false )

  echo "<h1>xxxx.com</h1>";

elseif( strpos( $_SERVER[ 'HTTP_HOST' ], "yyyy.com" ) !== false )

  echo "<h1>yyyy.com</h1>";

 

You could also embed this in a function to make the code cleaner.

 

function fromDomain( $domain ) {

if( strpos( $_SERVER[ 'HTTP_HOST' ], $domain ) !== false )

  return true;

else

  return false;

}

 

if( fromDomain( "xxxx.com" ) )

...

 

 

Hope this helps

TNX.

Thank you for your suggestions, i was having a few problems as I use a mac and it wouldn't let me save a .htaccess file (as the . makes it a system file so it becomes hidden)

 

If i were to use the code you gave me:

 

function fromDomain( $domain ) {

if( strpos( $_SERVER[ 'HTTP_HOST' ], $domain ) !== false )

  return true;

else

  return false;

}

 

if( fromDomain( "xxxx.com" ) )

 

 

Would I put that in the .htaccess file?

 

Also sorry to sound like a noob but which elements of the code need customising apart from the obvious "xxxx.com"

Hi LucyEleanor,

The way you want to change it is not i think by rewrite, that is sub domain for lucyeleanorbrown.com.

Anything before lucyeleanorbrown will be considered as sub domain, like project.lucyeleanorbrown.com.

 

So in this case login into your Cpanel and create new sub domain weddings under lucyeleanorbrown.com. That would be the way you want as what i get from your post.

 

Mod_rewrite is different thing, that is to rewrite the URL, not sub domain.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.