I've been trying along with NINTENDO to use htaccess to redirect a dynamic php file to another page, but without success. Can add I add any code to the page that when users or SE's visit this page they are redirected to say my homepage in way similar to a 301 so not to lose any reputation with SE? The page isn't needed anymore and if I just remove it I'll get lots of 404 errors, lost visitors and Google has about 500 pages of this page. Thanks Ian
I get an error: Warning: Cannot modify header information - headers already sent by (output started at /blah/blah/blah/folder/folder2/file.php:1318) in /blah/blah/blah/folder/folder2/folder3/folder4/file_top1.html on line 1 Code (markup): I placed this in file_top1.html, but this is a template that is called for the dynamic page. How do I get round this? Ian
The code I posted needs to be the first thing sent to the browser. If you have a template you may need to put it in the file that calls the template instead.
I've added this code and it all works fine, I presume when SE visit they will remove the old pages from their index and then at somepoint later I can completely delete the file?????? This is the URL can anyone tell me thsi is fine and will cause no SE problems: h tt p://w ww.costaandsierra.com/property_details/viewimage.php?imageID=319&type=listing <HTML> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="10; URL=http://www.site.com"> <TITLE>This page has moved</TITLE> <META http-equiv="Content-Language" content="en-us"> </head> <BODY> <br><br> <P>This page has moved all images are now located on each individual property for sale page.<br><br> </font><a href="http://www.site.com">Click here or wait 10 seconds to be redirected automatically to our home page</A> </p> </body> </html> Code (markup):
I am not sure this will work as it does not send the right headers to the search engine to say the page has moved. It will work to send your visitors on but I don't think it works as well for search engines. A quick google of this seems to agree with my point.
I think it is better if you you just redirect with the php. You also may want to make a sitemap of the urls that no longer exist. If you can get that page spidered and the se's to follow all the redirects with the 301 Moved Permanently header then you should see the old address removed and the new pages spidered much more quickly.
To avoid the headers already sent errors you could try putting ob_start(); at the top of your main php script and ob_flush(); at the end.
I've done it....I added your code to the viewimage.php along with all the headers like this: Do I need to change the actual headers that are shown below or anything else? I have the rest of the code below this. Once I see most SE have removed the index of the obsolute pages I'm safe to delete the file all together? <?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ht tp://www.costaandsierra.com"); exit(); ?> <HTML> <HEAD> <title>Title here</title> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <meta name="author" content="Ian Ainsworth"> <meta name="keywords" content="K W here"> <meta name="description" content="Desc here <meta name="distribution" content="global"> <LINK href="style here" type="text/css" rel="stylesheet"> </HEAD> Code (markup): Thanks Ian
you don't need anything after the <?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ht tp://www.costaandsierra.com"); exit(); ?>
Thanks Stuw, have removed everything. **Just 1 final question - I've got another site in Spanish language which I'll be doing the same with. I've used the following redirect in htaccess to change to SE friendly BUT to redirect to the homepage doesn't work it: RewriteRule ^viewimage.html viewimage.php RewriteRule ^viewlistingimage-([0-9]*).html viewimage.php?imageID=$1&type=listing So if I add the header("HTTP/1.1 301 Moved Permanently"); etc to viewimage.php will this cause problems with the htaccess saying one thing and the file doing another, all links in SE are viewlistingimage-numberhere.html Thanks Ian
The best thing is to try it and see the htacces will redirect the page before any scripts on the page have a chance to run. Therefore if the htaccess redirect is not working the php redirect will work fine.
This link claims to check if your redirect is SE friendly: http://www.webconfs.com/redirect-check.php
I would suggest just using .htaccess to do the redirection. It's not too tough. Just ensure that the file is names ".htaccess" (with the dot) and that it contains a line like this for every redirection you want: redirect 301 /oldpage.htm http://www.mysite.com/newpage.htm or redirect 301 /directory/oldpage.htm http://www.mysite.com/directory/newpage.htm Use the first option if the old page is in the root directory and the second if it's in a directory. Do note how the first parameter is just the page location whereas the second is the complete web address with the http and www. Hope this helps!