I've recently split my site into two, and moved one section to a new domain. So, I have a situation where I need to have users redirected from: www.olddomain.com/blog to www.newdomain.com/ Obviously, I need to keep my page/directory structure intact - so if the user was on www.olddomain.com/blog/category/post555 they need to end up on www.newdomain/category/post555 - you'll notice that the site has moved from a sub-directory to the root of the domain, which adds an extra dimension to my problem. I'm hosted on a Windows shared server, so I don't have the ability to use .htaccess - I HAVE to find out if there is a way to do it via PHP headers - if there isn't a way to do it, that's fine - but if it is possible, please help me out here I should also point out that I'm a complete PHP noob, so explain it as simply as possible.
I think that's possible... put the following at start of your page, that means, at the very very start so put this bit of php code even BEFORE THE DOCTYPE I'm not 100% sure if it works though, but I hope it does just replace blog with the correct directory and newdomain.com with your new domain for thank you message and fan mail: <?php $newurl=$_SERVER['PHP_SELF']; $newurl=str_ireplace("blog","",$newurl); $newurl="newdomain.com".$newurl; header('Location: '.$newurl); ?>
If the blog has been working with URIs like that then they must have been run through a URL rewriter. Being on windows doesn't restrict the use of .htaccess files, so long as the server is running Apache for the HTTP requests. Do you know what HTTP service is running?
That will work IF you could redirect to the file, otherwise you'd have to create a file for each and every URI in the blog!
Dude placing this scrip above <?php in the index file makes the job simpler <?php header("HTTP/1.1 301 Moved Permanently"); $request_url =$_SERVER['REQUEST_URI']; $via_url= str_ireplace("blog","",$request_url); $redirect_new_url = "http://newsite.com".$via_url; header("Location: $redirect_new_url"); ?> PHP: Thanks
Thanks for the replies guys - I'll play around with the suggestions and see what works. With regards to the HTTP service question - I have no idea. I'm on a shared server and I don't have admin access - unless you can suggest a way for me to check. I've tried testing an .htaccess - and all I've been able to confirm is that it doesn't work. So it looks like mod_rewrite isn't an option.
@roopajyothi - I'm perfectly aware of how bootstrapping/routing through an index.php file works. That isn't the issue. The problem is that you need to rewrite the urls to the file. Once they're routed to the file, yes your code will work, however you are missing the fundamental flaw in your process, without rewriting, every URL won't run through the index.php file
@sachamps - Go here and enter your url http://www.serverheader.com/getHeaders.aspx Then paste back the contents of the box that starts with Server:
url rewriting using htaccess will be best solution... using php isn't the best way... it will work fine only when each and every page runs through index.
If it is WP, then why don't you give some try to redirection plugins.. I haven used them... But kinda I feel its worth a try http://wordpress.org/extend/plugins/redirection/