Using php, how might I redirect all pages under a folder to a different domain?
Current site:
http://www.example.org/dept
http://www.example.org/dept/stuff
http://www.example.org/dept/more
http://www.example.org/dept/more/stuff
New site:
http://www.example-too.org/pets/stuff
http://www.example-too.org/pets/more
http://www.example-too.org/pets/more/stuff
I've learned about how to redirect a single page:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.example-too.org/pets/more/stuff" );
?>
but how to apply this to dozens of pages without creating a php redirect for each one?
[edit] I understand using web server config (apache mod_rewrite) and/or .htaccess is the best way to handle multiple redirects like this, but I those options aren't available to me.
thanks.
Worth mentioning that the better way to do this through "Redirect" command in the web server config or .htaccess
Unfortunately, unless one PHP script is used to handle all those URL's already, you need to create a new PHP script for each URL.
You could write some script to automate the process however.
For instance, if it is a Linux server and you are able to run shell scripts, something like this could work (execute in the htdocs folder, or equal):
If you are unable to run shell scripts, you could translate the script into PHP.
Thanks Mikael, I modified your script a bit to deal with my html pages instead of folders: