LucyEleanor Posted December 19, 2010 Share Posted December 19, 2010 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 More sharing options...
NONAME_2 Posted December 19, 2010 Share Posted December 19, 2010 Hi, Pzl See http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html(: Link to comment https://forums.phpfreaks.com/topic/222122-changing-a-web-address-using-php/#findComment-1149200 Share on other sites More sharing options...
NONAME_2 Posted December 19, 2010 Share Posted December 19, 2010 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. Link to comment https://forums.phpfreaks.com/topic/222122-changing-a-web-address-using-php/#findComment-1149208 Share on other sites More sharing options...
LucyEleanor Posted December 19, 2010 Author Share Posted December 19, 2010 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" Link to comment https://forums.phpfreaks.com/topic/222122-changing-a-web-address-using-php/#findComment-1149210 Share on other sites More sharing options...
mmarif4u Posted December 19, 2010 Share Posted December 19, 2010 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. Link to comment https://forums.phpfreaks.com/topic/222122-changing-a-web-address-using-php/#findComment-1149215 Share on other sites More sharing options...
LucyEleanor Posted December 19, 2010 Author Share Posted December 19, 2010 Ah that makes a lot of sense, Thank you. Link to comment https://forums.phpfreaks.com/topic/222122-changing-a-web-address-using-php/#findComment-1149217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.