Log in

View Full Version : htaccess php html



ggalan
12-02-2009, 04:30 AM
ive tried adding a htaccess file such as


AddType application/x-httpd-php .html

so that i can keep my file extension html. however it does not work. and i read this in a similar post

"SSI enabling is causing the problem. We also tested this using 2 external servers outside our network, one we disabled SSI and it worked and the second was a server with php loaded as an apache module with SSI enabled and it worked.
So we concluded that since PHP is loaded as a cgi and SSI is enabled then parsing PHP within an HTML file will not work."

does anyone know of a workaround?

thank you

traq
12-02-2009, 05:29 AM
This doesn't exactly address your specific question, but I'm wondering why you would want to keep your .html extensions. If you're using php code on your pages, why not change the extensions to .php? And, since you're using .htaccess already, you can use rewrite rules to redirect any .html requests to .php files (to accommodate old bookmarks, for example):

RewriteRule ^(.*)?\.html$ $1.php [NC,L]
corrected the regex. see my post below.

ggalan
12-02-2009, 05:47 AM
i want to keep the extension html because the site is currently in that format and changing it would have an effect on search seo

ggalan
12-02-2009, 05:54 AM
i placed this inside htaccess but it does not redirect html extensions to php


RewriteRule ^[(.*)].html$ $1.php [NC,L]

traq
12-02-2009, 06:52 PM
I'm sorry, I made a few typos:

RewriteRule ^(.*)?\.html$ $1.php [NC,L]
1. NO square brackets.
2. ESCAPE (backslash) the dot.
3. add a ? (ungreedy pattern match) after (.*)
In addition, you must have mod-rewrite enabled. You may have to do this by placing the line RewriteEngine on at the top of your .htaccess file.
This kind of redirect should not have any effect on your SEO. The url shown in the address bar will not change (e.g., it will still read "http://www.example.com/page.html", even though it's showing the user "page.php") because the redirect is done server-side. However, this means that ALL requests for .html pages will be served their .php equivalents, even if there isn't one... which could result in 404 errors. The easiest solution would be to rename ALL your pages with the .php extension.

ggalan
12-02-2009, 07:01 PM
so this is my htaccess file


RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [NC,L]


here is a test link: http://www.2020proj.com/notes/htmlphp/films.php
it still does not work

ggalan
12-02-2009, 07:02 PM
its linking but getting an error

traq
12-02-2009, 07:51 PM
did you put the question mark? it works on my server: http://www.custom-anything.com/htaccesstest/redirect.html (<-- actually a .php file)

ggalan
12-02-2009, 07:55 PM
where do i put the '?' mark

traq
12-02-2009, 10:20 PM
RewriteEngine on
RewriteRule ^(.*)?\.html$ $1.php [NC,L]

ggalan
12-02-2009, 11:05 PM
im following your directions but it still doesnt work. wonder if this has something to do with it<br>

"SSI enabling is causing the problem. We also tested this using 2 external servers outside our network, one we disabled SSI and it worked and the second was a server with php loaded as an apache module with SSI enabled and it worked.
So we concluded that since PHP is loaded as a cgi and SSI is enabled then parsing PHP within an HTML file will not work."

traq
12-03-2009, 01:50 AM
hmmm... I don't know about that. Might be, but I don't know.

Try the following:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)?\.html$ $1.php [NC,L]
"RewriteBase" is used to rewrite the URLs ("/" means the site root) - so put whatever path this .htaccess is saved to. e.g., If you saved this .htaccess to the root, leave it as is; if it's in a subdirectory, replace / with /path/to/subdirectory/ .

If that doesn't work, and if you're not getting any error messages, try this:


Bad Code Causes 500 Errors

or some other random text. If you don't get a 500 (Server) Error, that means your .htaccess file isn't even being read. It could have been saved or uploaded improperly (make sure you're uploading in ASCII mode). Or, try uploading it as htaccess.txt and renaming it after it's on your server.

If nothing works, then it may be time to ask your host what the problem might be, or if they even allow .htaccess files.

ggalan
12-03-2009, 02:12 AM
now its getting

Error 500 - Internal server error

An internal server error has occured!
Please try again later.

traq
12-03-2009, 03:19 PM
well... I don't know, then. the code in my post above (#12) is working perfectly on my server.

Maybe someone else can put in their two cents on the SSI issue.

ggalan
12-03-2009, 08:34 PM
thank you for all your help: )