Forum Moderators: coopster

Message Too Old, No Replies

Redirecting .html pages to .php

         

kenfused

5:44 am on Jan 22, 2006 (gmt 0)

10+ Year Member



Hello,
Right now my site is a mix of .html and .php pages...
I want to update everything so that the backend is all in php, but dont' necessarily want to update all my links.

I want say mysite.com/about.html to point to mysite.com/about.php IF that page "about.html" does not exist on the server.

To complicate things. I already have some rules in .htacces that will redirect things like mysite.com/article/35.html to mysite.com/article.php?=35

I want to redirect old html pages so that if someone follows an old link, it transparently brings up the .php page, without messing up my existing set of rules.

How do I do this?
Thanks

dreamcatcher

10:24 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Redirect permanent /relative_source_url [full_destination_url...]

or maybe:

Redirect temporary /relative_source_url [full_destination_url...]

dc

jatar_k

5:43 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why not just change your config so you can have the html pages parsed for php, then there is no need to change pagenames at all.

for apache
AddType application/x-httpd-php .php .html

twist

5:52 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Get rid of extensions altogether, never have to deal with this problem again.

kenfused

4:49 am on Jan 24, 2006 (gmt 0)

10+ Year Member



____________
For:

why not just change your config so you can have the html pages parsed for php, then there is no need to change pagenames at all.
for apache
AddType application/x-httpd-php .php .html
_______

What I want to make sure is that IF a .html page exists then it should use the original .html page, and IF a .html page doesn't exist THEN go to .php (same filename)
Will that be done with the above?
Or can I do this with a .htaccess?

latifrugs

2:40 pm on Jan 24, 2006 (gmt 0)

10+ Year Member



Not sure how you would do it for finding if it exists or not, but what you want is a mod_rewrite set of rules in .htaccess.

See this link:

[httpd.apache.org...]

Has all the info you need.

I guess the logic would be something like this:

try to match uri
if fail then try to map to similarly name php file (or use it as a string to the php file for processing correct data).

Something like:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([A-Za-z]).html$ $1.php [L]

Hope that helps.