Forum Moderators: phranque
I've got myself in a bit of a tangle and need to tidy my file structure up.
I have a couple of scripts that produce very similiar content. It seems that this could cause some duplication problems with Google so I've decided to set up a single php script to do the job that both are doing right now.
The first script is /cgi-bin/directory/file.pl?variable=something and this is how its listed in Google.
Looking thru the forum it seems I need to 301 the file to my new location. I want the new permanent location to be
/newdirectory/something.html where something was the posted variable. How can I do that in my htaccess file?
The second problem is my first try at mod_rewrite! I have a structure
/anotherdirectory/filename2.html that is a rewrite of a script similar to the first one at /cgi-bin/directory2/file2.pl?variable2=something Because of the rewrite Google lists the html pages rather than the script itself.
How can I 301 an infinite number of html pages to /newdirectory/something.html as well!
Any help would be appreciated! Thanks.
Welcome to WebmasterWorld!
Your questions aren't entirely clear to me. It would be helpful if you would post the code you have, describe what is does as compared to what you want it to do, and focus the questions a bit more.
I'm particularly puzzled by your question about an infinite number of URLs -- for two reasons: First, a query string is not formally part of a URL, but rather data attached to that URL to be passed to the resource at that URL. So, even an infinitely-variable query string is still attached to only one URL.
Secondly, mod_rewrite uses regular-expressions pattern-matching, so even assuming that you had a vary large number of files/pages in a subdirectory, a single rewrite could easily redirect all requests for resources in that subdirectory to another page, file, directory, or subdirectory, and it could even keep the original page/file identifier if that's what you want.
Take a look at the references provided in our forum charter [webmasterworld.com], and see if they help get you started toward a solution.
Jim
Thanks for your post and the welcome.
I have a Perl script that receives a variable 'something' and displays data for that variable. I wanted to 301 the script so that Google etc would see the new URL as /directory/something.html (which now rewrites to a new php page). I wanted to do this since php is easier to design visually and I wanted to separate the urls into a directory structure rather than thru a single script.
Hope this makes a bit more sense...
I found the following perl that I could use to do this. Do you think this would be OK?
$url='http://anydomain.com/directory/something.html';
print $co->redirect(
$url,
status=>301
);
print $co->start_html;
print $co->end_html;
Thanks!