I added the code below to my .htaccess file to enable caching files for 3 days. After that my website wasn't available anymore and I got a message displayed that told me it's an Internal Server Error
The code:
# 3 DAYS
<FilesMatch "\.(html|css|js|gif|jpg|jpeg|png|ico|swf)$"> Header set Cache-Control "max-age=259200, proxy-revalidate" </FilesMatch>
The message:
Internal Server Error
The server encountered an internal
error or misconfiguration and was
unable to complete your request.
Please contact the server
administrator, webmaster#exampple.com
and inform them of the time the error
occurred, and anything you might have
done that may have caused the error.
More information about this error may
be available in the server error log.
What is wrong with the FilesMatch or what else could cause the Internal Server Error?
Thanks
I had this issue a while ago, You can solve it by typing
"sudo a2enmod headers" in the command line
this is another solution
http://diogomelo.net/node/24
To enable this module, log in as root, and create a symbolic link from mods-available/headers.load to mods-enabled. After that, reload apache and it's done. To do so, I've used this commands.
su -
cd /etc/apache2/mods-enabled/
ln -s ../mods-available/headers.load headers.load
sh /etc/init.d/apache2 force-reload
After that procedure the issue is solved.
It has to be on multiple lines, not all in a single line. This one works fine for me:
<FilesMatch "\.(html|css|js|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=259200, proxy-revalidate"
</FilesMatch>
This is another possible solution, after applying multiple lines do this simple possible solution.
Problem:
You may have copied and pasted the htaccess instructions directly from a sample code on a website or a slide presentation or somewhere else which creates a problem with the text encoding format.
Solution:
Copy the code again but this time paste it on a simple notepad or text editor and then, copy and paste it again into the ataccess file. This will remove any encoding problem.
Another problem you can have which returns error 500 it's you don't have enabled the AllowOverride directive correctly on the Apache conf file.
Example:
<VirtualHost *:80>
ServerName yoursitename
DocumentRoot /var/www/html/site
<Directory /var/www/html/site>
Options -Indexes +FollowSymLinks +MultiViews
Require all granted
AllowOverride None
</Directory>
ErrorLog /var/log/apache2/error_site.log
On that sample there's one AllowOverride none which blocks all .htaccess modifications you can do.
You can remove that AllowOverride None or modify it allowing only the directives do you need. On the example you placed with AllowOverride FileInfo will be ok.
More info about the AllowOverride directive here: https://httpd.apache.org/docs/2.4/es/mod/core.html#allowoverride
Related
I'm working on a project in a group. I'm the only guy using Linux. Anyways, we use git and there's one file which causes me problems.
The htaccess contains the following:
<IfModule authz_core_module>
Require all granted
</IfModule>
If I comment out the Require all granted, it works, however, when it's not commented out, it gives me a 500 server error.
I do have authz_core_module and I can't disable it because if it's not a module it will Deny from all.
Why is that line giving me a 500 server error? The file works correctly at all those other guys who use Windows. Is it something because of my Linux apache?
I got it to work by adding these 2 lines to my httpd.conf file:
<Directory /THEPATHHERE/>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo Indexes Authconfig
</Directory>
I have difficulties making my .htacces work on my Ubuntu 14.04 LTS. I know it is a hidden file and all; I've searched everywhere and people seem to have the same problem. I've made a virtual host on my machine and all. Can someone please help me ?
ErrorDocument 404 /pages/error.php?code=404
ErrorDocument 403 /pages/error.php?code=403
You need to make sure the following things are true:
You need to check what DocumentRoot is set to. When an url beginning with a slash is detected, it will try to load that file relative to the document root. (docs) The file <documentroot>/pages/error.php must thus exist.
You need to make sure that .htaccess files are allowed by the main Apache configuration. The easiest way to test this is by entering garbage into your .htaccess file, saving it and reloading a page. You'll get an internal server error if Apache reads the .htaccess file. Otherwise the page loads as expected. To enable .htaccess files, the AllowOverride directive must allow something (see next bullet point). Additionally, check in httpd.conf if AccessFileName is set to something different than .htaccess. Change it as necessary, then RESTART APACHE. (docs)
For ErrorDocument, AllowOverride must be at least set to FileInfo. See the docs. Go to your main config file (httpd.conf), probably apache/Apachex.y.z/conf/httpd.conf. Search for the <Directory ...> block that corresponds to your http root, and look around if it contains an AllowOverride directive. Add FileInfo as one of the arguments, save the file and RESTART APACHE.
I want to disable the parsing of PHP files in a specific directory, and found out how to do that here. The problem is that my server uses PHP-FPM, and I get Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration when I try to use php_flag in my httpd.conf file.
How can I disable parsing of PHP files in a given web-accessible directory with an htaccess/httpd.conf file that is located above web root on a server using PHP-FPM?
Since Fedora 27 switched to php-fpm recently, I, too, ran into this problem. Unfortunately, the old ways of doing things with mod_php do not apply to php-fpm.
I did find another question here that definitely seemed more relevant:
Apache: Disable php in a directory
The gist of it was was to use a <directory> and <filesmatch> block in your config file, and use SetHandler ! for every directory you didn't want PHP code interpreted.
e.g.:
<Directory "/path/to/no/phpfiles">
<Files "*.*">
SetHandler !
</Files>
</Directory>
This is tested and working on Fedora 27, PHP-FPM 7.1.12.
Unlike using the fpm configs directly, this technique works recursively, so placing it at the top level of a tree of stuff you don't want PHP interpreting works as expected.
I disable .htaccess files in my configurations, but this technique should still work. However, <directory> is not valid inside a .htaccess file. Hopefully just removing it, and leaving:
<Files "*.*">
SetHandler !
</Files>
Should be sufficient.
How can I disable parsing of PHP files in a given web-accessible
directory with an htaccess/httpd.conf file that is located above web
root on a server using PHP-FPM?
You can't persay the way you're trying it without mod_php (which you don't want) which is why you're getting that error. PHP-FPM is not an Apache module. It runs independent of Apache. That's actually it's purpose to be used on heavily loaded sites and it can control all the PHP processes.
One way you might be able to achieve this is to specify the exact path you want to run PHP, in your virtualhost file with the Directory directive. Instead of just having the PHP handler stuff, enclose it with the Directory directive with the actual path you want it to run. Here is an example.
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html/
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/access.log combined
<Directory /path/to/php/only/folder/>
#then you PHP handler stuff
<IfModule mod_fastcgi.c>
AddType application/x-httpd-fastphp5 .php
Action application/x-httpd-fastphp5 /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi_example.com
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi_example.com -socket /var/run/php5-fpm_example.com.sock -pass-header Authorization
</IfModule>
</Directory>
</VirtualHost>
Then restart Apache. This should limit it to that directory. You might have to remove the php handler info from the other config so it's not overwritten.
Note I have not tested this solution.
I have just created a new (test) symfony project and set my apache webroot to /home/user/project/ (not sure if it should be /home/user/project/web/?)
However, from what I understand based on the lightbulb section here: http://symfony.com/doc/current/book/page_creation.html#the-web-directory - there isn't any internal rerouting occurring. Therefore, this does not work:
http://localhost/random/10
but these do work:
http://localhost/app_dev.php/random/10
http://localhost/app.php/random/10
To double check, if I start the internal PHP server (php app/console server:start) then everything gets rerouted correctly - this does work:
http://localhost:8000/random/10
Am I right in thinking that I need to make changes to .htaccess? If so, is there a 'standard' section of code for using apache with symfony?
EDIT:
I have updated my apache2.conf (which for others would be httpd.conf if not on ubuntu as I understand it) as below:
<Directory /home/user/Project/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
If I remember correctly, .htaccess alredy defines DirectoryIndex as app.php. However, your Apache config file httpd.conf might be blocking the override.
Make sure that you have that line in your .htaccess and also check the value of AllowOverride (docs) within your httpd.conf. Try setting AllowOverride to All and see if that works.
I have Ubuntu 12.10 with apache2 installed, and my .htaccess file is not working. I have it set up to be able to not have .php file extensions in the links, so it looks like www.website.com/login instead of /login.php, but it says that the URL "/login" is not found on the server. I have read this page and it says something about "AllowOverride All" but I don't know where that is, or if I need to add it, where I would add it.
EDIT: I have found this link and have found what it says, but it says that I have an Internal Server Error on any page I go to. I have changed the to
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
but it says Internal Server Error
EDIT #2: In the error log, it says
/var/www/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
EDIT #3: Found the answer here: .htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Make sure you have enabled mod_rewrite in your .htaccess.
Also make sure you these lines at the top of your .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
i.e. turn the MultiViews options off.
Also see this Q&A for a similar problem and my answer.
You should have or specify Directory-block in your apache configurations. You can find AllowOverride documentation here: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
And documentation about <Directory> is here: http://httpd.apache.org/docs/2.2/mod/core.html#directory
In short: specify where you would like to allow the settings to be overridden with <Directory /path/to/your/directory> and then use AllowOverride all in that directory block.