PDA

View Full Version : Can this be done any easier? Help!


explorer1987
02-03-2005, 06:03 PM
Hello everyone,
This is my first post in this forum and I'm a newbie to php. I have converted my .htm files to .php. Is there anyway to redirect visitors who request the URL with .htm extension (via search engines) to the file with the .php extension without having to add a redirect request for each individual file on my site. Your help is greatly appreciated.

xiaodao
02-03-2005, 06:14 PM
what do you mean by |withour haveing to add redirect request|

explorer1987
02-03-2005, 06:32 PM
Hi,
Via the control panel of my site I tried to add a redirect using the wildcard * for the server to redirects all requests to *.htm to *.php and it did not work so I'm assuming that in order for this to work one need to literally add a redirect request for each file by name. Is it the case?

Hawkmoon
02-03-2005, 06:51 PM
You can change the configuration file on the server so that .htm files get parsed by the PHP engine. IE, alter httpd.conf at the appropriate line to contain:
AddType application/x-httpd-php .php .phtml .php4 .php3 .html .htm

Unless you have root access on your server this will be pretty much impossible to do. (I don't know a server admin for a big hosting site that would do this). Another alternative - although you'll get some people who swear this is a bad idea - is to use an iframe. IE:


<html>
<head></head>
<body>
<iframe src='index.php'></iframe>
</body>
</html>


-Hawkmoon

explorer1987
02-03-2005, 07:04 PM
I tried adding a mime type but it didn't work and I guess this is because the file with the .htm extension does not exist anymore since it has the new .php extension.

Hawkmoon
02-03-2005, 07:18 PM
Yeah...if the .htm file is gone then links there are all gonna be bad. Hopefully you have a common entry for you application/websites like index.htm So just create the following:

index.htm

<html>
<head>
<script language='JavaScript'>
function redirect() {
location.href = 'index.php';
}
</script>
</head>
<body onLoad='redirect()'>
Redirecting...
</body>
</html>


Then with index.php have all the links and urls navigate to .php files.

explorer1987
02-03-2005, 07:46 PM
thanks for all your hel Hawkmoon, but unfortunately this is not what I'm looking for. The issue is with files listed with search engine since they last crawled the site. They all have the files listed as .htm which no longer exist since I changed the file type to .php. Is there any script to execute even if on the error page 404 so that the visitor can be directed to the new .php page instead

Hawkmoon
02-03-2005, 08:04 PM
Just wanna get you up and running on PHP :)

It sounds like you have root on your server so the only other thing that I can think of is to setup custom 404 PHP error pages that redirect to the correct page.

http://www.onlamp.com/pub/a/onlamp/2003/02/13/davidsklar.html

explorer1987
02-03-2005, 09:45 PM
Thanks a lot :thumbsup:
I was able to do a redirect thru .htaccess via this command in case someone needs to use it:
RedirectMatch (.*)\.htm$ http://www.yoursitename.com$1.php
this means no more .htm files on my site for now untill search engines crawl my site again (hopefully not before long). :)

Hawkmoon
02-04-2005, 12:36 AM
That's great!

Good to have you on the forum. Looks like you've got a solid background in Server admin stuff. Yeah?

firepages
02-04-2005, 03:11 AM
looks like you are sorted now but there was really no need to change the file extensions in the first place , .. unless you had a specific reason, you could have simply added

AddType application/x-httpd-php .php .htm

to a .htaccess file in your document root (unless your httpd.conf is particulary restrictive)

explorer1987
02-05-2005, 04:48 PM
Hawkmoon I figured that out from the link you gave me, and as I said earlier I'm newbie to most of this. I agree with firepages but unfortunatley I found that out after the fact. So if someone is thinking of doing this and still has his/her files in .htm extension do what firepages suggested as that will be a lot easier.

pixelpets
02-06-2005, 06:12 AM
there's always a way to redirect. although i don't know the scripting for it but you can program a url to go to a different link in so many seconds. you can also have a freewebs.com site and make it say example.com instead of freewebs.com for example but i think you need a software for that, if thats what your asking