disable lookup for .htaccess file in subdirectories via .htaccess in root - apache

Is it possible to disable lookup for .htaccess file in subdirectories, when I know I will only need my .htaccess in root directory?
I know it can be done with "AllowOverride None" when you have access to the server configuration file. But can I do this with my .htaccess file in root as well?

No. It must be done inside a <Directory> directive, which can only exist inside core configuration files.

Related

Rewrite rules in Apache

Can anybody tell me where to put Rewrite rules in httpd config file and tell me also how can I write rules in different file and include that file in httpd config file
Rewrite rules in a separate file go in the hidden .htaccess file. This file goes in the public webserver's folder where you want the rules to apply and it is applied in a way that it respects .htaccess files on higher folder hierarchy.
For .htaccess files to be considered you need to add AllowOverride All in the Directory Tag where your server is configured.

Redirect request to folder with .htaccess

How can I set .htaccess to make
http://www.example.com/folder
go to (assuming this is not made automatically)
http://www.example.com/folder/ ?
For existing directories, Apache already provides a configuration option via mod_dir. Add the DirectorySlash directive to your main configuration file, or otherwise the root .htaccess file.
DirectorySlash on
See the documentation.

Alias Directive for shared hosting

How would I indicate Alias directives on shared hosting.
The file I want to serve is located:
home/user/public_html/the_file_I_want_to_serve.html
I would like to serve the file described above in:
home/user/desired_folder/subfolder1/subfolder2/HERE
I read the Apache's documentation on Alias directives, but I am unsure if I place directives in public_html/.htaccess or in desired_folder/.htaccess
Then I wonder, would directives in htaccess recognize a folder outside of its domain?
the url to load home/user/desired_folder/subfolder1/subfolder2/HERE is a subdomain like temp.domain.com which points to home/user/desired_folder/subfolder1/subfolder2
The Alias directive is not allowed outside of the server/vhost config. Since the htaccess file is a "per directory" context, there's no way to do anything outside of the context of the document root. Which means you can't do/know anything outside of the root (which I'm assuming is /home/user/public_html/. You'd have to move the "desired_folder" into the public_html directory, or at least symlink it from the public_html directory.

Is it true that httpd looks for .htaccess files in all higher-level directories?

Given the directory www/html/file.php would it be it be appropriate to place my .htaccess alongside with file.php?
That way making rules for file.php (demo example below)
~Rule~ file.php ...
file.php would be located.
No. It depends on the setting of AllowOverride for specific directories - however, in most configurations AllowOverride is enabled for the document root.
See http://httpd.apache.org/docs/current/de/howto/htaccess.html#page-header
According to that documentation, you should put any rules into the global configuration file instead of .htaccess files if possible. if you can't access the global configuration file, you should put the .htaccess file into the folder it applies to.

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.