Is there a way for Apache to silently ignore unrecognized .htaccess directives? - apache

I'm in the unfortunate position of having an Apache staging server combined with a Zeus web server. (Not my choice).
I'd like to be able to include a Zeus-specific directive in the .htaccess file (e.g. ContentCompressionEnabled) and, if possible, include the Apache equivalent (AddOutputFilterByType DEFLATE) in the same file too.
Is there a way of doing this which doesn't involve separate .htaccess files for Zeus and Apache?

Only in 2.4, where there is an Nonfatal option to AllowOverride.

If I understood correctly, you can use httpd.conf file do this configuration for all requests. .htaccess file configurations effect only requests to where the file located.

You could put any Apache only directives into either Apache's main httpd.conf file, or the sites vhost config file - along with AllowOverride None.
This would mean that Apache would get all it's config info from there and ignore any .htaccess files completely.
You could then place anything you wanted in the .htaccess files, including all the Zeus config you need - and Zeus would be configured only from there - thus separating the two configs.

Related

Can't remove index.php without 404 error

I'm using Joomla 2.5 and Apache and I have followed this steps:
1- mod_rewrite module is eneabled? YES
2- htaccess.txt renamed to .htaccess
3- set "Use URL Rewriting" to YES.
And this is what I get:
Not Found
The requested URL /about-us was not found on this server.
The web is located in /var/www/
The .htaccess is located in /var/www/
And this is my .htaccess: http://pastebin.com/dq1TYs1t
Thanks for the help.
Since you said allowoverride was set to none, your .htaccess file will be ignored. You need to set allowoverride to all the other option is leave allowoverride at none, and take the contents of the .htaccess file and incorporate it into your apache configuration file. This has the benefit of being slightly faster as apache doesn't need to look in directory tree for .htaccess files (they are really good to allow users that don't have access to the configs the ability to override the base settings, but if you have access to /var/www you should also have access to make changes to the config files.
There is no need to enable any mod_rewrite module.
Need to enable URL rewriting option in global configuration. Also need to rename htaccess.txt file to .htaccess.
please check there is no any third party component of security like admin tools are enable or installed which is blocking this mod rewrite option.

Difference between httpd.conf, php.ini and .htaccess

I am about to start learning Apache. All resources I am looking into, mention either php.ini, or .htaccess or httpd.conf files for setting configurations and stuff. But none of them are clear on the difference between these 3 files. Can anyone explain the difference and their usage?
httpd.conf (it can actually be named differently on some platforms, but that's the default) is the master configuration file for Apache. You can use Include statements to pull in external configuration files. httpd.conf is read in when Apache starts or if you run a 'reload'.
.htaccss is a per-directory configuration file for Apache. You can enable or disable the use of .htaccess files in your httpd.conf file. Where possible its been recommended to me to turn .htaccess use off, as Apache will check the file every time a request causes it to read the directory.
PHP is, as you probably know, separate from Apache, although often used with it. php.ini is the configuration file for the PHP engine.
Every daemon or application has it's own configuration files. On linux these are often located in the /etc directory. You will have to learn to edit each one according to the program. the /etc/php5/php.ini is different from the /etc/apache2/httpd.conf and so on.
Think of them like different types of files. a Word document is not the same as a JPEG Image or a AVI video.
The PHP.ini controls PHP's settings
The .htaccess controls apache settings for a given folder (and all child folders)
The httpd.conf controls apache's settings.
php.ini is a configuration file where you specify options for things
related specifically to php, for instance CURL
.htaccess is where you specify options for URI routing and folders
options on your server
httpd.conf is a configuration file where you specify options for
things related specifically to apache

Set path to php.ini

Is it possible to have just a single php.ini file, for example in the webroot (or even outside of it to prevent people accessing it via GET), and tell PHP quickly and easily where it is?
I know you can set php.ini directives in .htaccess, but is it possible to define a specific php.ini file to be used?
Add this to your server configuration...
<VirtualHost 1.2.3.4:80>
PHPINIDir /path/to/new/php_ini
</VirtualHost>
Make sure to just include the path to the directory, not the entire path to the file.
Then restart Apache.
Check it worked with phpinfo().
Have a look at .user.ini section at the php docs.
Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on
a per-directory basis.
But beside the .unser.ini solution you can place an additional ini file in the "additional .ini files parsed" directory. There you can use one single ini file to overwrite all other settings. Name it with zzz at the beginning and it will be parsed at last. This is also easy for your hoster to deploy without destroying his settings.
Kolink, I suspect that you are on a shared hosting service, in which case your host may be using something called suPHP. In this case -- as you describe -- the PHPINIDir directive doesn't work, in which case there is a suPHP_ConfigPath directive.
In terms of access, I have a standard mod_rewrite in my DOCROOT/.htaccess:
RewriteEngine On
RewriteBase /
# if a forbidden directory or file name (starting with a . or /) then raise 404 Fatal
RewriteRule (^|/)[_.] - [F]
What this does is forbid any request for any filename or directory prefixed by . or _. I have a DOCROOT/_private where I keep this stuff for me:
suPHP_ConfigPath DOCROOT/_private
where you will need to replace DOCROOT by your local setting on your service. Look for DOCUMENT_ROOT in a phpinfo() listing.

PHP: How to code .htaccess to make it work both on localhost & online without editing

I have a .htaccess file & I currently I am working on localhost. For a 404 page error, I have the following code in the .htaccess file:
ErrorDocument 404 /my_local_domain/404.php
But when I upload this file to my website online, the functionality of the file breaks. It no longer shows the 404.php page. It works if I modify the code in the .htaccess file of my online website to the following:
ErrorDocument 404 /404.php
Now all through the changes that I do in the .htaccess file, I would have to remember to remove the domain name before I upload it to the website or I risk breaking the functionality. So with this in mind, here are my questions:
1. How do I solve the above problem without needing to edit the .htaccess file each time (by stripping it off the my_local_domain) I make a change & upload it online?
2. How do I setup 404 page redirection for all the nested folders? (I don't want to setup a .htaccess file for each of the folders. A single .htaccess file that resides in the root folder of the website & controls all the redirection for all the sub-folders would be awesome)
All help is appreciated.
Thank you.
I believe you have two different issues here.
First of all, you should not need to have different paths in development and live site. It appears that you've configured your local Apache to host only one site and each actual sites goes in a subdirectory. It's not a good idea: you'll soon be mixing cookies and sessions between all your dev sites. Have a look at the name based virtual hosts feature: you can configure as many independent sites as you need. You don't even have to buy real domains in you set them in the hosts file.
Secondly, under certain circumstances it can be useful to have different Apache directives. I've been using the following trick.
Pick a keyword for the dev server, e.g. DEV_BOX.
Pass that keyword to Apache in the -D parameter. If you run it as service, you can run regedit and find the HKLM\SYSTEM\CurrentControlSet\Services\Apache2.2\Parameters key. Append -D DEV_BOX to the ConfigArgs value. Restart Apache.
Now, you can use the <IfDefine> directive to set local directives:
-
#
# Common stuff
#
AddDefaultCharset UTF-8
#
# Local-only stuff
#
<IfDefine DEV_BOX>
Options +Indexes
</IfDefine>
#
# Live-only stuff
#
<IfDefine !DEV_BOX>
Options -Indexes
</IfDefine>
First of all I suggest you setup local domains for development. For example if you are developing a website which will go under www.example.com, you can setup a local.example.com in your HOSTS file. You'll do a VirtualHost setup in your apache and the .htaccess will then be the same.
Also, you can setup a build process (e.g via Ant) which will allow you to prepare and generate a zip file with the files which go on the live server. This build will feature the correct configuration files (db configs, mail servers, htaccess etc).

identify Apache config directive

My website has a file: www.mydomain.com/contact.php
If I request any of the following (which do not exist), apache serves the contact.php page.
www.mydomain.com/contact
www.mydomain.com/contact/
www.mydomain.com/contact/anything/else/here
How can I determine what part of the apache config to change to disallow this?
The apache server is running on a CentOS 5 box if that makes any difference.
This is called MultiViews.
A .htaccess file or modifying your httpd.conf with Options -MultiViews should do the trick.