[Question] URL Change in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TiagoCT
Forum Newbie
Posts: 2
Joined: Wed May 13, 2009 1:23 pm

[Question] URL Change in PHP

Post by TiagoCT »

Hi everyone!

I own a website, for example http://www.example.com.

And I also bought a domain on Lunarpages for example: http://www.my-domain.net

After a long time writing to the Lunarpages Staff I finally got them to
create a Redirect to my (http://www.example.com) Website.

The problem is, I would now want to change my URL in http://www.example.com
to http://www.my-domain.net.

Please note that Lunarpages gives me absolutely no control over my Domain.
That's why I'll switch to GoDaddy within a Year. So...my only option would be to
edit the PHP code in http://www.example.com to only show http://www.my-domain.net on the
Address Bar.

I mean...instead of doing it on the Lunarpages Domain, I want to do it on the exact Website
I'm redirecting to.

Is this possible?

Thank you in Advance.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: [Question] URL Change in PHP

Post by crazycoders »

if you have access to HTACCESS addAction i would recommend using a strapping method to switch your users from one domain to the other...

In an .HTAccess file write this:

Code: Select all

 
AddAction redirect .php
AddAction redirect .html
AddAction redirect .jpg
AddAction redirect .gif
AddAction redirect .png
Action redirect redirect.php
 
Then in the redirect.php file you do a simple:

Code: Select all

 
header('location: http://'.$newdomain.$_SERVER['PATH_TRANSLATED']);
 
This is not tested and is off the top of my head, but the method is accurate and if htaccess/addaction is supported at lunarpages, you will be able to redirect everyone to your new domain with a little work!

Cheers
TiagoCT
Forum Newbie
Posts: 2
Joined: Wed May 13, 2009 1:23 pm

Re: [Question] URL Change in PHP

Post by TiagoCT »

Thank you for the reply.

Unfortunately, I don't think this will help me because I have no control
over my domain. I can't access any server files or settings.

This would have to be done only through PHP.

I mean, in the begining of the code of a page, is there any sort of code I can use
to switch what is presented in the Address bar?

Instead of using redirects and that sort of thing I just want to be able to switch
what's on the Address bar.

Javascript is accepted too.

Once more, thank you for your help,

Tiago
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: [Question] URL Change in PHP

Post by crazycoders »

No, what is shown in the address bar is what the browser is fetching for the user, you can't change that unless you redirect the user to the newer domain.
Post Reply