.htaccess with XAMPP on Windows7

Problems with the Windows version of XAMPP, questions, comments, and anything related.

.htaccess with XAMPP on Windows7

Postby MikeatAFF » 04. December 2014 21:59

I've exhausted my resources. I could use some help here.

I installed XAMPP successfully on my Windows 7, 64 bit machine. I placed my webpages in C:\xampp\htdocs\mywebsites. I can now use Microsoft Expression Web 4 to modify and Preview my pages. The HTML and PHP pages are working.

Now I want to configure the Apache with an .htaccess file so I can open .html files that have php code in them. Without the .htaccess file, then any pages that have php code must be saved with a .php extention or they won't load correctly when viewed in a web browser. I have a .htaccess file on my Godaddy web server (that uses Apache on linux) that is working so that my previously existing html files can contain php code. I don't want to change all my pages to .php because there may be many links and bookmarks out there to the html pages. I just want to now add more functionality to them with php code. But no matter what I do, I can't seem to get the .htaccess file to work with my local Apache server at all.

I put the local .htaccess file in the C:\xampp directory. It contains the same text as the .htaccess file that I put on Godaddy's web server:

Options +ExecCGI
AddType application/x-httpd-php .php .htm .html
AddHandler x-httpd-php5-cgi .php .htm .html

I've tried everything I could find on the web: I went to the host file at C:\Windows\System32\drivers\etc\ and uncommented (took out the #) 127.0.0.1 localhost. I also opened the httpd.conf file and uncommented LoadModule rewrite_module modules/mod_rewrite.so. I changed Options Indexes FollowSymLinks to Options Includes Indexes FollowSymLinks MultiViews. I changed all the AllowOverride None to AllowOverride All (perhaps I did not need to do all of them for security reasons). I searched for AddType application/x-gzip .gz .tgz and added the following line under it: AddType application/x-httpd-php .php. I even opened httpd-xampp.conf and changed all the AllowOverride None to All (I don't know if this is needed). Still the .html and .php pages seem to work. But I still cannot open any .html pages with php code in them.

Any help would be very much appreciated. Thanks.
Last edited by MikeatAFF on 05. December 2014 00:58, edited 2 times in total.
MikeatAFF
 
Posts: 5
Joined: 04. December 2014 01:38
Operating System: windows 7

Re: .htaccess with XAMPP v3.2.1 on Windows7

Postby Nobbie » 04. December 2014 23:24

What do you enter in the Browser in order to open your local files?
Nobbie
 
Posts: 13182
Joined: 09. March 2008 13:04

Re: .htaccess with XAMPP on Windows7

Postby MikeatAFF » 05. December 2014 00:16

I can either Preview in Expression Web 4 (EW4). Or I can open a browser and enter the URL of http://localhost/mywebsites/thisbsite.com/Aphpinhtmltest.php. This works for either .html pages (with no php code) or .php pages. But when I change the .php extension to .html and try to open the .html in a fresh browser, it displays a dialog box asking me if I want to open or save the file Aphpinhtmltest.html. This is rather odd behavior. But I know it is the XAMPP that is displaying the pages because the browser returns an error unless I go into the XAMPP control panel and start Apache.
MikeatAFF
 
Posts: 5
Joined: 04. December 2014 01:38
Operating System: windows 7

Re: .htaccess with XAMPP on Windows7

Postby Altrea » 05. December 2014 01:37

in \xampp\apache\conf\extra\httpd-xampp.conf replace the following line (line 21)
Code: Select all
<FilesMatch "\.php$">

with this line
Code: Select all
<FilesMatch "\.(php|html)$">

save the file and restart Apache.

No need for an additional .htaccess
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: .htaccess with XAMPP on Windows7

Postby MikeatAFF » 05. December 2014 02:46

Thank you, Altrea. I tried your suggestion. And it seems to work, almost.

The .html with php code now processes the php as desired. The .html pages with no php also work. But now the .php files, with or without html code, does not work. It only shows in the browser all the <html> tags, as if viewing the source code. Do I need to undo all the changes I made in the original post? Or maybe I should just uninstall and reinstall XAMPP and then make the changes you suggest.
MikeatAFF
 
Posts: 5
Joined: 04. December 2014 01:38
Operating System: windows 7

Re: .htaccess with XAMPP on Windows7

Postby Altrea » 05. December 2014 07:29

MikeatAFF wrote:Do I need to undo all the changes I made in the original post?

yes

MikeatAFF wrote:Or maybe I should just uninstall and reinstall XAMPP and then make the changes you suggest.

a good idea too
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: .htaccess with XAMPP on Windows7

Postby MikeatAFF » 06. December 2014 01:24

Thanks again, Altrea. It all seems to be working now. The html only pages work. And php code in html pages work (which is what I was going for). The php only pages work. And the html in php pages work. I think that's it.

I had to reinstall XAMPP after all those changes I made. And I confirmed that no changes mentioned in the original post are implemented. All I changed was line 21 of \xampp\apache\conf\extra\httpd-xampp.conf. I changed it to <FilesMatch "\.(php|html)$">. And everything seems to work. Thanks.

However, shouldn't that have been changed to <FilesMatch "\.(php|htm)$">, so that the $ would be replaced with the letter "l"? Then .htm file would work with php code in them too, right?

Actually, I just tested line 21 changed to <FilesMatch "\.(php|htm|html)$">, and everything seems to work fine.
MikeatAFF
 
Posts: 5
Joined: 04. December 2014 01:38
Operating System: windows 7

Re: .htaccess with XAMPP on Windows7

Postby Altrea » 06. December 2014 12:41

MikeatAFF wrote:However, shouldn't that have been changed to <FilesMatch "\.(php|htm)$">, so that the $ would be replaced with the letter "l"?

no. The $ stands for "end of the string". It makes sure that the searchstring is the end of the filename and not something in between.
Otherwise other filenames like "test.html.jpg" etc would match too.
But you could do something like <FilesMatch "\.(php|html?)$">
(The ? if placed after a character is a quantifier and stands for 0-1, so the l at the end of html can be there 0 or 1 times)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 128 guests