Redirect request to folder with .htaccess - apache

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.

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.

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.

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

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.

Trouble shortening my MediaWiki site URL? Where is <directory> directive?

I am using a basic hosting plan on Host Gator. I installed MediaWiki and I am getting URLs with index.php?title= in it, i.e. www.domain.com/index.php?title=Main_Page
I want to remove the index.php?title= part and just have the title of the page appear. I am following the instructions from http://www.mediawiki.org/wiki/Manual:Short_URL/Page_title_--_Windows_%26_Apache_without_403_on_Special_Pages, not sure if this is the right instructions I should be using.
Step 1 of the instructions indicate that "If you have vHosts configured, insert the following Rewrite directives into the appropriate <VirtualHost> directive. Otherwise, insert it in the <directory> directive for your wiki's root directory:" and to insert:
RewriteEngine On
RewriteRule ^/(.*):(.*) /index.php/$1:$2
Where is the <directory> directive located? What file should I be inserting the code into?
The <directory> block is a httpd.conf Apache configuration file directive.
On a shared hosting enviroment, you don't generally have directly access to his file. You still have access to an .htaccess file, which allows most configuration directives to be used.
Create a .htaccess at your web root (the same directory you have index.php and LocalSettings.php) and write the RewriteEngine / RewriteRules directives in this file.
If this fails, follow instead this guide, more adapted to your situation:
http://www.mediawiki.org/wiki/Manual:Short_URL/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.