Forum Moderators: phranque

Message Too Old, No Replies

html parse php

html parse php through htaccess

         

elvisjj

6:14 pm on May 10, 2008 (gmt 0)

10+ Year Member



Hi,
When I added the following code to .htaccess I am getting "500 internal server error". I tried many methods in this forum but in vain. So please assist me to overcome this problem. Thanks.

AddHandler server-parsed .php
<Files ~ "^[^\.]+$">
SetHandler application/x-httpd-php
</Files>
AddHandler application/x-httpd-php .php

Note : mod_rewrite is already enabled.

jdMorgan

6:18 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post the relevant contents from your server error log file.

Thanks,
Jim

g1smd

6:23 pm on May 10, 2008 (gmt 0)

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



# Set the PHP Include Path

php_value include_path /apache/htdocs/thesite/includes

# Allow .html .htm .asp extensions to be PHP scripted files:

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

# Force Download, Not Open in Browser, for PDF, ZIP and DOC files:

AddType application/octet-stream .pdf .zip .doc

Marcia

6:34 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't even need to use any regular expressions. Many threads here about this:

parse html for php [google.com]

Nothing fancy is needed. It does sometimes vary from host to host (with shared hosting), some need AddType and some need AddHandler.

jdMorgan

7:09 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



elvisjj is saving CPU time by NOT processing files for PHP if they have a period in their name. However, that word "files" needs to be emphasized, because if a URL resolves to a filename with an extension, then it will not be processed for includes.

Since <Files> does not use mod_rewrite, it is irrelevant to this case whether mod_rewrite is enabled or not.

Jim

Marcia

7:26 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>word "files" needs to be emphasized, because if a URL resolves to a filename with an extension, then it will not be processed for includes.

How about pages ending with /? I don't recall seeing sites having pages both with and without a file extension, but it gets confusing because there are some new blog/cms themes that use filename endings like /foo - wouldn't those automatically put a forward slash at the end?

jdMorgan

7:46 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



URLs do not matter, <Files> means files, and their names.

Correct "page" URLs do not end with "/" since a "/" at the end of a URL denotes a directory, not a page. The "index page" is an exception, because the DirectoryIndex directive can be used to map a request for the directory URL "example.com/" to the file for the example.com/index.xyz page.

You can end "page" URLs with a slash if you like but it's just not orthodox, and may cause unforeseen problems in handling by the client (e.g. search engine robots).

It pays to think about URLs, directories, and files as separate (even if slightly overlapping) concepts.

The main job of a server is to translate URLs to filepaths, independent of the filesystem structure and naming conventions used by that server's operating system.

The reason I emphasized the point about <Files> applying to filenames and not to URLs is that it is very likely that almost every URL on elvisjj's site will resolve to a filepath which includes a period and a filetype, so it's possible that that <Files> directive is not going to work as elvisjj expects it to.

Jim

elvisjj

3:45 am on May 11, 2008 (gmt 0)

10+ Year Member



Thank you very much for all of you. First I will clear what is the problem with my website.

I am using a dedicated server and hosting with ixwebhosting. So I am unable to access the server config files. I am only able to add anything through my Cpanel only.

I am using a script for my website where in the admin panel I have an option " Search Engine Optimized links ON / OFF - it will make .html extensions for articles and categories with their title respectively".

When turned on
"http://example.com/articles.php?art_id=1&start=1 ----> http://example.com/article/default-article-1-1.html" and
"http://example.com/category.php?cat_id=1 ----> http://example.com/category/default-category-1-1.html"

Once again I am typing the code in my .htacces file which is placed in the root directory

AddHandler server-parsed .php
<Files ~ "^[^\.]+$">
SetHandler application/x-httpd-php
</Files>
AddHandler application/x-httpd-php .php

If I placed the above said .htaccess file I am getting "500 Internal Server Error" and if I remove .htaccess file I am getting "Error 404: File Not Found".

Once again Thank you for all of you helping me.

[edited by: jdMorgan at 4:45 am (utc) on May 11, 2008]
[edit reason] example.com [/edit]

jdMorgan

4:37 am on May 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post the relevant contents from your server error log file.

Thanks,
Jim

elvisjj

5:03 am on May 11, 2008 (gmt 0)

10+ Year Member



[Sun May 11 01:00:28 2008] [error] [client 218.248.68.198] Request exceeded the limit of 20 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Sun May 11 01:00:28 2008] [error] [client 218.248.68.198] Request exceeded the limit of 20 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Thanks,
Elvis.

elvisjj

12:49 pm on May 11, 2008 (gmt 0)

10+ Year Member



One more information my server runs php in cgi mode.

Thnaks,
Elvis.

jdMorgan

1:56 pm on May 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, that's a good indication of a bad error. I don't know why you would get internal recursion from adding or changing AddHandler/SetHandler though.

You said you cannot change your server config file, but can you "see" it? Can you get a listing of what is in there?

My only thought at the moment is that you may need to *disable* your Control Panel SE-Friendly URLs, and then replace that function in your own .htaccess file; It sounds like the SEF code generated by your control panel is buggy.

Jim

elvisjj

4:29 pm on May 11, 2008 (gmt 0)

10+ Year Member



My server config data

<VirtualHost *.*.*.*:*>
ServerAdmin webmaster@example.com
DocumentRoot /hsphere/local/home/user/example.com
ServerName example.com

ServerAlias www.example.com
d3888636.u78.*.examplehosting.com example.*.examplehosting.com

User user
Group user

<IfModule mod_php4.c>
AddType application/x-httpd-php .php3
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
</IfModule>
<IfModule mod_php5.c>
AddType application/x-httpd-php .php3
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
</IfModule>
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
ScriptAlias /cgi-bin "/hsphere/local/home/user/example.com/cgi-bin"
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
TransferLog /hsphere/local/home/user/logs/example.com/example.com
ErrorLog /hsphere/local/home/user/logs/example.com/error_log
AddType text/html .shtml
AddHandler server-parsed .shtml
AddType text/html .html
AddHandler server-parsed .html

<DIRECTORY /hsphere/local/home/user/example.com>
OPTIONS Indexes Includes ExecCGI FollowSymLinks
AllowOverride All
</DIRECTORY>
IndexOptions FancyIndexing
</VirtualHost>

<IfDefine SSL>
<VirtualHost *.*.*.*:*>
ServerAdmin webmaster@example.com
DocumentRoot /hsphere/local/home/user/example.com
ServerName example.*.examplehosting.com

ServerAlias www.example.com
d3888636.u78.*.examplehosting.com example.com

SSLEngine on

<IfModule mod_php4.c>
AddType application/x-httpd-php .php3
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
</IfModule>
<IfModule mod_php5.c>
AddType application/x-httpd-php .php3
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
</IfModule>
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
ScriptAlias /cgi-bin "/hsphere/local/home/user/example.com/cgi-bin"
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
TransferLog /hsphere/local/home/user/logs/example.com/example.com
ErrorLog /hsphere/local/home/user/logs/example.com/error_log
AddType text/html .shtml
AddHandler server-parsed .shtml
AddType text/html .html
AddHandler server-parsed .html

User user
Group user
<DIRECTORY /hsphere/local/home/user/example.com>
OPTIONS Indexes Includes ExecCGI FollowSymLinks
SSLOptions +StdEnvVars
AllowOverride All
</DIRECTORY>
SSLCertificateFile /hsphere/local/config/httpd/ssl.shared/*.examplehosting.com/server.crt
SSLCertificateKeyFile /hsphere/local/config/httpd/ssl.shared/*.examplehosting.com/server.key

IndexOptions FancyIndexing
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</VirtualHost>
</IfDefine>

Thanks,
Elvis.