Forum Moderators: phranque

Message Too Old, No Replies

edit .htaccess with apache on XP

to parse html as php files

         

tbear

11:24 pm on Oct 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK, I'm very new to all this.

I finally got the XAMPP package working on my home PC (Win Xp pro). HURRAH!

Now I would like to add the following to the .htaccess file:
AddType application/x-httpd-php .htm .html

I'm stumped :(

The hosting I use has a handy control panel, which makes this stuff easy.
It could be that this is a simple thing to do. I just haven't found the way, yet.
Could someone please point me in the right direction.
I'm not looking to learn all about Apache servers, etc, I just want to use it, to test my pages with php includes and slowly learn more about php and mysql.

The above might be a stupid question, but I prefer to feel stupid for 5 minutes than stay stupid the rest of my life, ;)

jdMorgan

2:32 am on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is your question, "How do I modify my existing .htaccess file?", or do you want to create a new one?

The usual method is to use a plain-text editor such as Notepad to edit or create the file.

The directive:


[url=http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addhandler]AddHandler[/url] server-parsed .html

is an easy way to parse .html-named files for php. I do not recommend that you change the MIME-type as you have shown, because that will result in the php-containing files being downloaded as code to the client browser, instead of being executed on your server.

Jim

tbear

12:31 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hmmmm, I'm sure I have seen the code I used suggested here. It seems to work fine on my sites too. However, I am more than pleased to discover the correct way of doing things, whenever possible.

When I get my offline server working correctly (LOL), I can then play around and learn a little more about how these things work :)

What I am doing is using php includes in html pages. I would like to see the pages, with includes, displayed in my browser, without physically changing the html pages to php pages.

As to the problem I have currently, there already exists a .htaccess file, in htdocs/forbidden/.

When I open it in notepad (or arachnophilia) it shows the following:
AuthType Basic
AuthName "FORBIDDEN AREA"
require valid-user
AuthUserfile "../htdocs/forbidden/.htpasswd"

Which I take to mean, this is not the way to approach this....:(

When I enter the page [localhost...] in my browser,
after supplying the user:password, I get the following:
Apache/2.0.54 (Win32) mod_ssl/2.0.54 OpenSSL/0.9.8 PHP/5.0.4 mod_autoindex_color Server at localhost Port 80

which I don't understand either :)

Reading your response, are you saying that just opening the .htacces file and adding the code desired and just 'plopping' it back where it was is sufficient?
That would be great!

Er, just to complicate things, there are two flys in the ointment:
1/ I have been reading about modifying the httpd.conf file which I have found in xampp/apache/conf (there I go, poking around again). Is this a better way forward?
2/ There seem to be two htaccess files :(, one in htdocs/forbidden, one in webdav/....

As you can see, I have been poking around, but am a little shy of messing around with things too much, just in case it goes feet up!

I am pleased for any light shown, on what appears to be a very dark pathway, so far, but very exciting, none the less ;)

jdMorgan

2:40 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.htaccess is a "per-directory" configuration file. That is, you can have one in each and every Web-acessible directory on your server, and each one can configure that particular directory in a different way.

So you need to create a new .htaccess file in the directories where you want html files parsed for PHP, or in any directory above those directories. The simplest case is to create a single .htaccess file in your 'Web root' directory -- the directory where your site's 'home page' resides. Any config set in that .htaccess file will then apply to the home page directory and to any subdirectory of your home page directory -- unless explicitly overridden by another .htaccess placed into one or more of those subdirectories.

Jim

tbear

3:05 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hah!
Excellent, thank you Jim!

Works a dream....:)

Although I did have to copy and past the .htaccess file from forbidden and change it, because windows wouldn't let me leave the file without a name, LOL.

Thanx again....
Ted

jdMorgan

6:00 pm on Oct 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The usual approach is to save the file on your Windoze box as "dot.htacess.txt" or similar, edit it, upload it, and then rename it to .htaccess on the server.

Jim