Readers like you help support MUO. When you make a purchase using links on our site, we may earn an affiliate commission. Read More.

I would like www enforced and file structure intact.

e.g. http://subdomain.domain.com/ants.php redirects to http://www.newdomain.org/ants.php

e.g. http://newdomain.org/dogs.php redirects to http://www.newdomain.org/dogs.php

Would I also use an add-on domain? Or would a parked domain be better?

Tina
2010-07-02 18:10:00
Rebecca,were Aibek's or Rob's pointers helpful? Please let us know whether your found a solution to your question. Thank you!
rob
MAKEUSEOF VIDEO OF THE DAY
SCROLL TO CONTINUE WITH CONTENT
2010-05-29 19:19:00
OK, I know you said PHP, I'll come on to that but first consider whether you can use the .htaccess fileThis does call for a good understanding of .htaccessThe official documentation isn't for the faint hearted so look for internet tutorials in something approaching normal English! Example: http://www.yourhtmlsource.com/sitemanagement/urlrewriting.htmlfor example in htaccess forcing www would look like this (untested)Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^yoursite.com [NC] RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301] OK so now for PHP, not sure why Stev C suggestion of isn't what you want so my answer may get you no further forware either.I'll assume you do know PHP so only outline how I'd try to tackle it:Create a redirect.php, it will only run as a server side program and never displays anything to the browser, instead it captures and redirects other requests.Read one of the system variables like _SERVER["SCRIPT_URI"] that will give you a string something like http://subdomain.domain.com/ants.phpHave a switch statement to switch according to the value of that variable.The individual cases should then say something like:Header( "HTTP/1.1 301 Moved Permanently" );Header("Location: http://www.newdomain.org/ants.php");break;Now replace each web page you want redirected with a copy of redirect.php so when someone requests http://subdomain.domain.com/ants.php the server runs a copy of redirect.php which has been renamed as ants.php and serves up the new page at http://www.newdomain.org/ants.phpYou could make more complicated decisions by slicing the _SERVER response string. For example you could do a redirect of any without the www element to the same page with www - but not on the same domain as the individual page name is the same whether the domain has www prefix or not.Not sure MUO is the best place for a programming question like this though, you may do better on a PHP specialist forum.
Aibek
2010-05-29 13:38:00
Do you want to redirect just one page or an entire website? D you have an access to the the server of the http://subdomain.domain.com ?
Rebecca
2010-05-29 21:32:00
I want to redirect an entire website!Hmm, server? Well I can modify files from cpanel and through ftp...
Aibek
2010-05-30 11:14:00
Rebecca, It should be fairly easy to do using .htaccess file placed in the directory corresponding to subdomain.domain.com on your server. (It can be accessed via Cpanel or FTP)If you're running Wordpress there are very a bunch of simple Wordpress plugin that can do that for you.
Steve Campbell
2010-05-24 19:07:00
Rebecca,This should help you out some:http://www.webconfs.com/how-to-redirect-a-webpage.phpI'm not sure it makes a difference how you have your domain. Best to just try it out and see what works.
Rebecca
2010-05-28 18:28:00
I tried that. That code does take me to the new URL but it doesn't carry the files over.