I have tried to run php in .html file and failed despite trying all solution suggested here. Someone suggested it maybe because Apache is not setup to accept .htaccess overrides. Maybe that is the reason. Now the question is how do I setup Apache?
To be able to use .htaccess files, the directive AllowOverride must be set for the directory into which you want to put .htaccess files. E.g.:
<Directory "/usr/local/httpd/htdocs">
AllowOverride All
</Directory>
This must be set in the core httpd.conf file of Apache. If you're on a shared host, you likely have no access to that (and that's correct, for security reasons).
Related
I upgraded a digital ocean box from 14.04 to 16.04 and ran in to some issues. The .htaccess file is not being parsed. I can throw garbage at the top of the file which normally breaks a server and it does not matter, leading me to believe it is not being parsed. My ultimate goal is to parse html files as php.
Virtual host settings were not changed after upgrade and worked before.
You can see an instance of the test droplet here: http://162.243.70.81/
I spent about 3 hours digging through other solutions including:
Checking conf file:
//Part of conf file
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Checking if rewrite module is enabled
Module rewrite already enabled
service apache2 restart
Review .htaccess file (this is the first few lines and the random chars should result in a 500 if working)
kldlkldfg
AddType application/x-httpd-php .html .inc
editing mime types and looking if some php extensions are not commented out.
When I did the upgrade I did keep old conf files when it said the previous were modified and offered to overwrite or keep. I kept the defaults. Keep in mind everything worked before the upgrade and can be seen at www.pylamdyes.com
When I upgraded to php7 I had to disable php5.
That is all of the relevant info I can think to give, happy to try anything or post specific info as requested. Thanks for looking at this.
Define your virtualhost correctly by removing the <Directory /> entry and use this instead:
<Directory /var/www/www.pylamdyes.com>
Require all granted
Options FollowSymLinks
AllowOverride all
</Directory>
About Directory / it should be in server config (outside virtualhosts) like:
<Directory />
Require all denied
AllowOverride none
</Directory>
Also note: if you have access to the server configuration, there is no reason to use .htaccess files. .htaccess files are meant for people without admin rights to configure the web server.
If you need access for another directory, such as the target for that Alias, then define it in the same fashion as the documentroot Directory entry I defined. Policy is and should always be, deny all to /, and give access to the specific directories from where you serve files.
Actually my project is in WordPress. I'm changing my server from windows to Linux.
After changing this I'm facing this error!
Why isn't my .htaccess supporting the Linux server?
If you're using Apache, you should configure it in order to allow .htaccess files to be executed.
To do so, you can
Create a virtual host, that configures specifically one site. Using a virtual host you can set a domain name, document root, server alias, etc. Also, you can set Allowoverride to All (or other). See AllowOverride
Set your configuration in /etc/apache2/apache2.conf (or /etc/apache2/httpd.conf in some versions). In these files, there is a <Directory "/var/www/" that points to your /var/www/ directory. Inside this Directory tag, you can set AllowOverride to All. Using this configuration, every site on your server will be allowed to use .htaccess.
I recommend to use the Virtual Host that allows a easier and cleaner configuration.
Checkout the comment in .htaccess file, if it starts with // then change it to #
For me this solved the problem, I wish for you too.
I tried to allow access to a directory by using the .htaccess file.
This is my .htaccess:
<Directory Bilder_Team>
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
The directory is "Bilder_Team". If I open the link to this directory, it shows me
500 Internal Server Error
How can I fix this?
Use this htaccessCheck for future checks or problems. Your problem as you could see, once checked, is that you are not allowed tags such as <Directory> in .htaccess files.
Instead put the .htaccess directly into the Build_Team directory and leave off the surrounding tags.
Possibly, a bigger problem is the use of AllowOverride None, which disables the use of .htaccess files and, obviously, has no part of any .htaccess file. AllowOverride directive can only be part of the main config file!
As shown the snippet is correct iff put in the httpd.conf file (name could vary). Which actually, if possible, is the better way to do it.
For more information about security concerns, you could refer to this StackOverflow answer.
Hope this helps!
I'm having a problem where it seems like my Vagrant VirtualBox isn't reading the .htaccess file for a site I have mapped out. (a proccesswire site)
I've don't know enough about Vagrant to find where I should be editing the directives so that my .htaccess file will be read. As far as I've gathered from searching I need to set a directive like so:
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
It seems the primary offender is the AllowOverride is typically set to "None" and needs to be "All". But I have put this in a httpd.conf file in apache and I'm guessing that isn't correct.
A bit more information: When I installed PW in the site root I got this error: " Unable to determine if Apache mod_rewrite (required by ProcessWire) is installed. ". As a result when I try to access a part of the CMS, that is usually handled by rewrite rules, the url (/admin or /processwire by default) just reroutes me to the homepage.
Also, I can delete everything in .htacess or add garbage to it and no errors occur. This tells me that .htacess isn't even being read.
I appreciate the help.
There's a server for which I don't have access to the control panel; I can only access a directory by FTP.
I need to know if the Apache AllowOverride directive is enabled in that directory.
I want to check that Apache has mod rewrite enabled and that the options allow Override All.
How do I do it with a PHP script?
Thanks
I don't think there's any way to do that in PHP. The only way is to put some commands into .htaccess that depend on AllowOverride and mod_rewrite, and see if you get 500 Internal Server Error when you visit the directory by web. For example, you can put
Options all
to test AllowOverride Options,
Allow from all
to test AllowOverride Limit, or
RewriteRule .* -
(which does nothing) to test mod_rewrite.