The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Forwarding .html pages to new .php extensions
nWo Sting
post Jan 8 2010, 06:38 PM
Post #1


Member
***

Group: Members
Posts: 63
Joined: 5-November 06
Member No.: 709



If I have an existing website that I want to redo and convert to php, (the extensions are currently in .htm), is there a way to have all the .htm extension pages automatically forward to their new php extensions without having to go into each page and add a forwarding code? thanks
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Jan 8 2010, 06:54 PM
Post #2


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



The Apache module mod_rewrite can be used for this sort of thing. See:
http://httpd.apache.org/docs/2.2/rewrite/

In particular, see this example:
http://httpd.apache.org/docs/2.2/rewrite/r...d-compatibility
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jan 9 2010, 01:35 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



I think it is much more sensible just to make the .htaccess settings to have .htm(l) files parsed as php.

Logically, if mysite.xyz/fishcookery.htm is a page about fish cookery, it makes no difference to the visitor whether the page is generated by php or anything else. Suppose something better than php comes along, you won't want to change the URLs again, will you?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
nWo Sting
post Jan 9 2010, 02:53 AM
Post #4


Member
***

Group: Members
Posts: 63
Joined: 5-November 06
Member No.: 709



QUOTE(Brian Chandler @ Jan 9 2010, 12:35 AM) *

I think it is much more sensible just to make the .htaccess settings to have .htm(l) files parsed as php.

Logically, if mysite.xyz/fishcookery.htm is a page about fish cookery, it makes no difference to the visitor whether the page is generated by php or anything else. Suppose something better than php comes along, you won't want to change the URLs again, will you?


Thanks for answering guys. Here is what I am doing, I made a site a few years ago and did not use CSS, also used an outdated program to build it with, so I am basically going to redo the whole site correctly. However some of the new action scripts I want to use are in php, that means the pages they are on have to be php for them to work, right?

Since I am redoing the whole site anyway I can also change it to php. I was concerned with forwarding the existing .htm pages to their new extension, especially for people who come to the site through a search engine which is still going off the old .htm extension.

I have never converted an html site to php, what is the easiest way to get all the pages forwarded? Would Brian's suggested way work? What would the exact code have to be that I put in the .htaccess file?

thanks
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jan 9 2010, 03:36 AM
Post #5


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE
...I am basically going to redo the whole site correctly.


OK, but "correctly" isn't quite right -- try to do it better, but as long as it works the old site was not "incorrect"(!)


QUOTE
However some of the new action scripts I want to use are in php, that means the pages they are on have to be php for them to work, right?


If you mean the address must be something.php, then no, this is not true. Something has to tell the server (Apache, etc) to pass files to the php interpreter -- it's just that usually this happens by default if the filename is xxx.php. There are also different ways to run the php interpreter: if you want to keep files it uses away from public view on a shared server, you need to use some kind of "wrapper" script so that the interpreter runs as user You (Me), rather than as "Nobody", or whatever Apache runs as. So my lines in .htaccess look something like this, but you will need to read up on your hosting service docs:

CODE

Action application/x-pair-sphp4 /cgi-sys/php-cgiwrap/<USERNAME>/php4.cgi
AddType application/x-pair-sphp4 .php .htm


Please remember you are not converting "from HTML". You had (static) html files, now you are going to use PHP to generate (more or less dynamic) files, but they are still html files.

Are you going to "reorganise" the site, so all the page names are completely different? (Bad Idea!) If not, I see no reason to change the file names: what the user sees is still an html page.

It all comes down to "programs and data". Like "style and content", the first really big step is understanding the distinction, but the equally important second step is realising that the disctinction really isn't quite that clearcut. If you have a page which is a "program" -- for example a search page -- it seems somehow more reasonable to call it search.php, because it's unlikely you will ever write exactly the same program in a different language. But if the page is "data", such as fishcookery.htm, then the program that happens to be churning it out really is irrelevant.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 9 2010, 05:39 AM
Post #6


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(Brian Chandler @ Jan 9 2010, 09:36 AM) *

my lines in .htaccess look something like this, but you will need to read up on your hosting service docs:

Yes that looked slightly Pair-centric. I've used this with various web hosts:

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



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
nWo Sting
post Jan 9 2010, 03:42 PM
Post #7


Member
***

Group: Members
Posts: 63
Joined: 5-November 06
Member No.: 709



QUOTE(Brian Chandler @ Jan 9 2010, 02:36 AM) *

If you mean the address must be something.php, then no, this is not true. Something has to tell the server (Apache, etc) to pass files to the php interpreter -- it's just that usually this happens by default if the filename is xxx.php. There are also different ways to run the php interpreter: if you want to keep files it uses away from public view on a shared server, you need to use some kind of "wrapper" script so that the interpreter runs as user You (Me), rather than as "Nobody", or whatever Apache runs as.


The site I am doing this change to is on its own server, not shared. I was under the assumption that in order to get php codes (like php include codes, or php action script) to work on the page, then I thought I was going to have to change each page to something like this

CODE

<html>
<head>
<title></title>
</head>
<body>
<?php ?>
</body>
</html>


Are you saying I can keep the file extensions the way they are with the .htm, but then just add this following code in order to get whatever php script I am adding to work properly? (along with changing .htaccess)

CODE

<?php ?>



QUOTE
Are you going to "reorganise" the site, so all the page names are completely different? (Bad Idea!) If not, I see no reason to change the file names: what the user sees is still an html page.


Well I have to go through page by page to add the correct codes for CSS, also clean up some stuff that is not needed, but no I do not want to reorganize the site. I want to keep all the pages on the same URL they are currently on. The great thing is with this new HTML editor I have I can change a whole bunch of pages all at once to save time.

Since I was adding php script I thought the site could no longer have the .htm extension, actually someone else told me that too but it seems like he may have been wrong. he told me that if I kept the extension at .htm then none of the php codes would work right.

QUOTE
If you have a page which is a "program" -- for example a search page -- it seems somehow more reasonable to call it search.php, because it's unlikely you will ever write exactly the same program in a different language. But if the page is "data", such as fishcookery.htm, then the program that happens to be churning it out really is irrelevant.


I was planning on adding a php search engine for my site. I currently use the Google Search box you can make in AdSense, it works great but I want my own search engine. I will probably be asking about making one of these too eventually.


By the way this is what is currently on my .htaccess file.

CODE

ErrorDocument 404 /404.shtml
AddHandler server-parsed shtml html htm

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+\.php$ /bogusfile



Should I add what Christian recommended of:
CODE


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



thanks guys!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jan 9 2010, 03:56 PM
Post #8


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Not while you still parse the same pages for SSI...

QUOTE
AddHandler server-parsed shtml html htm
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jan 9 2010, 07:22 PM
Post #9


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE
The site I am doing this change to is on its own server, not shared. I was under the assumption that in order to get php codes (like php include codes, or php action script) to work on the page, then I thought I was going to have to change each page to something like this


If you enable .htm pages for PHP parsing, with whatever server directive it is, then they will all be passed through the PHP interpreter, which will look for any bits of PHP program it needs to execute. But you don't "have" to change anything -- the plain html pages will pass through unchanged.

Normally the first thing you will want to do is replace the hand-copied navigation bits on each page by something generated by PHP (might be a simple "include", but typically you want each page to be slightly different, at least in not including a silly link to itself). As you do this the PHP interpreter will start to be doing useful work.

If you are currently using SSI to include a menu or whatever, well, yes you'll need to replace this all in one go, because either the pages are processed for SSI or for PHP; it's not easy (IIRC) to do both.

QUOTE
... he told me that if I kept the extension at .htm then none of the php codes would work right.


This is really not correct.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
nWo Sting
post Jan 9 2010, 08:45 PM
Post #10


Member
***

Group: Members
Posts: 63
Joined: 5-November 06
Member No.: 709



QUOTE(Brian Chandler @ Jan 9 2010, 06:22 PM) *


If you are currently using SSI to include a menu or whatever, well, yes you'll need to replace this all in one go, because either the pages are processed for SSI or for PHP; it's not easy (IIRC) to do both.


Yes I am using SSI for the include codes, I will switch those over to php include code when I make the site changes.

Thanks to everyone for all your help. My problem was listening to some guy from another html forum that told me that I needed to make all my .htm extensions say .php, I will make sure I only come to this forum for questions like these so I know that I am getting the correct answers.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
nWo Sting
post Jan 12 2010, 01:08 AM
Post #11


Member
***

Group: Members
Posts: 63
Joined: 5-November 06
Member No.: 709



hey guys I have another question in regards to this. I know Brian said not to run both SSI and PHP include at the same time, so I can only have one of these on my .htaccess at a time?

CODE

AddHandler server-parsed shtml html htm


CODE

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


The reason why I ask is because I am currently using SSI, and the only way for me to preview my new pages is for me to add the second code in relation to the php includes and codes that I am adding to the .htm pages.

The problem is that when I add the second php code to .htaccess it shuts off the SSI for the entire site, even on the pages that I have not added any php code too.

Is there any way to run both? At least until I change all my pages to php include codes? Otherwise I will have to keep changing htaccess back and forth when I do test previews of my updated pages, thanks.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Jan 14 2010, 01:54 AM
Post #12


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



A lot depends on how your server is set up. But you may be able to make a 'test' directory, with its own .htaccess file, and just use php in that. When it's all working you can switch over.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 02:50 PM