Jump to content

Archived

This topic is now archived and is closed to further replies.

brittny85

Redirects

Recommended Posts

I am working on converting a site that I made when I only knew HTML to PHP. I want to avoid link rot but I'm not sure what the best way is to go about doing so. It is a relatively large site so if possible I would like to avoid having to write a redirect page for each individual page. Essentially every page that was originally .htm will now be .php so that I can make use of the capabilities of PHP on each page, but with the same filename otherwise. Is there an easy way to go about doing this? I'm trying to think if I can just write a php script on my 404 page that will check if the link they were looking for was .htm and try first to redirect them to a page with the same name but ending in .php, but I don't know how to do that. If the best way is just to put a re-direct link in each individual file, what is the "correct" way to do so? Most of the places I have looked have said to use a META redirect, but I also saw on w3.org that that was a deprecated way of doing so. I don't have access to reconfigure the server. Any suggestions would be very welcome!

Thanks!
-Brittny

Share this post


Link to post
Share on other sites
you can use mod_rewrite to redirect the .htm pages to .php

Just google it and you'll find tons of tutorials

Share this post


Link to post
Share on other sites
Thanks!  That was really helpful and a good start.  But the more I try to work with this the more I agree with what it says at the beginning of the Apache manual mod_rewrite article about it being voodoo- cool voodoo- but still voodoo.  I thought I understood it, but since it isn't working, I must not be as close as I thought.  After looking at lots of different docs I came up with this for my .htaccess file:
[code]LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
Options +FollowSymLinks

RewriteEngine on
RewriteRule ^.+(\.htm)$ $.php [R=301,L] [/code]

For awhile I somehow had it so that it would redirect all of my .css files to .php (that was fun... not) but it never seems to do the same thing for the only file type that I thought I was specifying- .htm.

Thanks!
-Brittny

Share this post


Link to post
Share on other sites
you can also throw this into an .htaccess file

[code]AddType application/x-httpd-php .php .htm[/code]

this will parse html as php.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.