301 Redirect

Steve202

Free Member
Nov 19, 2008
176
35
Hi guys,

When I designed my original website, I used purely html but over the next couple of weeks I'm going be converting it over to php. Would it be possible to redirect users that come on the html page to the php version of the page using 301 redirects?

So, if the users comes in on contact.html it automatically directs them to contact.php.

Cheers
Steve
 

That Guy

Free Member
Dec 23, 2008
1,683
236
UK
In your .htaccess file add this:

Code:
[FONT=verdana][SIZE=2][COLOR=#000000]RewriteEngine On 
RewriteBase / 
RewriteRule ^/(.*)\.[B]html[/B]$ /$1.[B]php[/B][/COLOR][/SIZE][/FONT]

Should work as long as all the file names stay the same. For example:

contact.html will need to be contact.php


Let me know if it works :)
 
  • Like
Reactions: Steve202
Upvote 0

KM-Tiger

Free Member
Aug 10, 2003
10,346
1
2,893
Bexley, Kent
Upvote 0

edmondscommerce

Free Member
Nov 11, 2008
3,653
628
UK
If I were you, I'd do the reverse: set up a rewrite rule so that your php pages present as html. This way your URLs won't change at all, and you won't be tying yourself to php in the future.

this is the best idea

you can also adjust apache to parse html files for php as well if you want

Edit /etc/httpd/httpd.conf. Look for a line that says


AddType application/x-httpd-php .php .php3 .phtml

Add ".html" to that line.

Restart the server.
 
Upvote 0

Latest Articles