.htaccess set phtml to be run as php - .htaccess

AddHandler application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php .php5 .php4 .php .php3 .php2 .phtml
...within a .htaccess file but my .phtml files are not running as php, they're just showing the code!
Have I missed something?

Is your server configured to read .htaccess files? To test this simply write random content in it. If the server still works the file is ignored otherwise it returns a 500 Internal Server Error.
To enable .hhtaccess file support in your configuration use the AllowOverride directive.

Related

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

in htaccess file causes page to download. what I can. PHP version: 5.6.30.

how can I cache all files forever in .htaccess except .html and .php

Here is my current .htaccess file
#tell browser how to deal with compressed content
<Files *.css.gz>
AddType "text/css" .gz
AddEncoding gzip .gz
</Files>
<Files *.js.gz>
AddType "application/javascript" .gz
AddEncoding gzip .gz
</Files>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 2592000 seconds"
ExpiresByType text/html "access plus 1 seconds"
</ifModule>
<ifModule mod_headers.c>
<filesMatch "\.(js|css|png|jpg|ico|pdf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
</ifModule>
RewriteEngine on
RewriteBase /
#Cache-Friendly File Names
RewriteRule ^(.*)-([0-9]+)\.(.*)$ $1.$3
#try to use precompressed files whenever possible
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
RewriteRule ^(.*)\.css$ web_inc/$1.css.gz
RewriteRule ^(.*)\.js$ web_inc/$1.js.gz
The web page is mostly static .html files and large .js and .css files that use ajax calls for any dynamic content. Since all files in the html are refereed to by name-01.js if I make an update to the .js I just increase the version number and the browser recaches.
I wish to prevent the web browser from ever redownloading any file type except .html or .php. Is there a way to not have to list every file type I use and how can I explicitly set php to 0 sec for mod_expires?

.htaccess Process html files like php

I've been trying to get .HTML files to process like .PHP files using the .htaccess file on my localhost. I've used the following one by one,
AddHandler application/x-httpd-php55 .html .htm
AddHandler application/x-mapp-php55 .php .html
AddHandler application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5-script .html .htm
But none of the above worked for me.
I am using php5.5 and apach 2.4 in xampp
Is there any other configs in apache config file?
Need help
This question is clear, but no proper answers yet given. It seems nobody can answer it. Too bad, but it can happen
This has worked for me in the past.
AddHandler application/x-httpd-php .html
Also note that you must have mod_mime activated in Apache.
Also I assume your server is allowing the use of an .htaccess file and the AddHandler directive with either :-
AllowOverride All
or
AllowOverride FileInfo
My DEV HTACCESS looks like this
<IfModule mime_module>
#AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
AddType application/x-httpd-php .php .htm .html .shtml
</IfModule>
I switch the Hashing for LIVE server though.
Hope this helps

short url's using htaccess

I want to make short url's in my web for ex:
change this url:
www.site.com/somepage.php
www.site.com/text.php?id=123
to this:
www.site.com/somepage
www.site.com/text/123
I tried alot of example from answers here and nothing work, I dont konw what I'm doing worng.
my default htaccess file is:
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/user/php.ini
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
What I need to do for making it work?
You have to define a rule and active the URL Rewriting :
#URL Rewriting
RewriteEngine on
RewriteRule ^somepage$ /somepage.php [L]
#Your code
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/user/php.ini
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php

Access phppgadmin from another computer?

I have installed phppgadmin in a Ubuntu server and want to access it from another computer.
It said access denied when i typed:
http://<ip>/phppgadmin
The port 5432 is opened in the Ubuntu server but just for local ip.
Thanks
The /etc/apache2/conf.d/phppgadmin.conf configuration file by default keeps anyone but localhost from accessing PhpPgAdmin.
Add a line that makes a new allow rule for your IP, so it looks something like this:
<Location /phppgadmin>
Order deny,allow
Deny from all
Allow from [Your client IP]
</Location>
By the way, this kind of question is probably more appropriate for stackoverflow's sister site serverfault.com
I know this is an old question but since i stumbled on it trying to fix the "Failed to load resource: the server responded with a status of 403 (Forbidden)" error while trying to access phpPgAdmin from another computer and the given answers didn't work for me, I wanted to share my solution.
Ubuntu: 17.04; phpPgAdmin: 5.1
Solution:
Comment out Require local in /etc/apache2/conf-enabled/phppgadmin.conf and restart apache (sudo service apache2 reload)
<Directory /usr/share/phppgadmin>
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
AllowOverride None
# Only allow connections from localhost:
# Require local
<IfModule mod_php.c>
php_flag magic_quotes_gpc Off
php_flag track_vars On
#php_value include_path .
</IfModule>
<IfModule !mod_php.c>
<IfModule mod_actions.c>
<IfModule mod_cgi.c>
AddType application/x-httpd-php .php
Action application/x-httpd-php /cgi-bin/php
</IfModule>
<IfModule mod_cgid.c>
AddType application/x-httpd-php .php
Action application/x-httpd-php /cgi-bin/php
</IfModule>
</IfModule>
</IfModule>
</Directory>
/etc/apache2/conf-enabled/phppgadmin.conf
This is an apache (or web server) issue. You're phppgadmin directory has a .htaccess file disallowing EVERYONE except localhost.
You need to either set it to Allow ALL or Allow (insert IP here)
Are you running Apache?
You need to change your permissions in the httpd.conf file or .htaccess
http://httpd.apache.org/docs/2.0/misc/security_tips.html
I want to share my solution as well.
Debian 10.1 with Apache 2.4.38 and phpPgAdmin 5.1 on 64-Bit ARM.
The following config will allow local and LAN access, but (for security reasons) NO WAN access.
/etc/apache2/conf-enabled/phppgadmin.conf
<Directory /usr/share/phppgadmin>
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
AllowOverride None
# Only allow connections from localhost:
#Require local
Order deny,allow
Deny from all
Allow from ::1
Allow from 127.0.0.1
Allow from 192.168.0.0/16
Allow from 172.16.0.0/12
Allow from 10.0.0.0/8
<IfModule mod_php.c>
php_flag magic_quotes_gpc Off
php_flag track_vars On
#php_value include_path .
</IfModule>
<IfModule !mod_php.c>
<IfModule mod_actions.c>
<IfModule mod_cgi.c>
AddType application/x-httpd-php .php
Action application/x-httpd-php /cgi-bin/php
</IfModule>
<IfModule mod_cgid.c>
AddType application/x-httpd-php .php
Action application/x-httpd-php /cgi-bin/php
</IfModule>
</IfModule>
</IfModule>
</Directory>

Resources