Questions tagged [.htaccess]

Directory-level configuration file found mostly on Apache web servers

The htaccess file is a supplemental configuration file used by Apache to modify the default configuration as it applies to the directory the htaccess file it in (as well as all the files and subdirectories in that directory).

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
Source: Apache manual

The directives allowed in htaccess files are governed from the main Apache configuration files by means of the AllowOverride directive.

The most common use is in conjunction with the mod_rewrite and security modules of the Apache webserver. Mod_rewrite allows URLs to be rewritten for scenarios such as the following:

  • Shortcuts such as example.com/info to redirect to another page
  • Redirects from old pages to new pages
  • virtual directories (directories which actually appear elsewhere in the file system)

The most common security applications are:

  • Password protection of directories and files

For more information see the mod_rewrite and aaa documentation.

2807 questions
5
votes
1 answer

.htaccess RewriteRule not working

I have a windows environment using WAMP where this works fine. I am just setting up my Ubuntu desktop development environment, and this particular mod_rewrite is not working. It's pretty basic, but if I go to example.local/files/a-real-file.pdf I…
Chad
  • 163
  • 1
  • 5
5
votes
3 answers

Need help finding what is wrong with my .htaccess not being read

I'm trying to use mod_rewrite through the .htaccess files and I have a big problem, the .htaccess files don't seems to be read. The machine is running Debian 5.0 and it's using the stable apache2 package. I've followed instructions from this page:…
Nicolas Buduroi
  • 275
  • 3
  • 11
5
votes
1 answer

Apache Adds Trailing Slash Despite RewriteRule

I'm using a simple .htaccess to handle everything with a PHP script: RewriteEngine on RewriteRule . index.php My index.php just echoes server variables at the moment (with a print_r($_SERVER)); Everything works fine, I type anything in the…
sidyll
  • 75
  • 1
  • 7
5
votes
0 answers

Environment variables not available on server after mod_rewrite, but works locally

I am working on a site where I am using SSI to set a variable on an HTML page that gets parsed and the variable is then to be picked up by a script after a mod_rewrite rewrite. This works on my local setup, but for some reason it doesn't on the…
5
votes
3 answers

Permission denied: Could not open password file.

I am using Apache Red hat . I have .htaccess in my /var/www/html with permissions as followed -rwxr-xr-x. 1 apache apache 127 Dec 18 14:17 .htaccess .htaccess has following data set inside it AuthType Basic AuthName "Restricted…
user1486269
  • 53
  • 1
  • 1
  • 4
5
votes
3 answers

AH01630: client denied by server configuration Apache

I get this error when trying to access localhost via a browser. 403 Forbidden I use Ubuntu 14.04 LTS Here is my configuration file: etc/apache2.conf # This is the main Apache server configuration file. It contains the # configuration directives…
Koulapic
  • 59
  • 1
  • 1
  • 2
5
votes
1 answer

Don't use htpasswd if coming from local host

I have a development site that, for an additional layer of protection to keep preying eyes away, I have behind a htpasswd file. However, I'm getting tired of typing in the username and password when I'm running test on the server. So I thought it…
Scott
  • 199
  • 4
  • 6
5
votes
2 answers

Redirecting from http to https in Apache

This is a canonical question about redirecting from http to https in Apache Related: Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask I have an Appache web server which serves both http://example.com/ and…
Augustin
  • 117
  • 2
  • 6
5
votes
2 answers

htaccess order Deny,Allow rule

I'd like to dynamically add IPs to a block list via htaccess. I was hoping someone could tell me if the following will work in my case (I'm unsure how to test via localhost). My .htaccess file will have the following by default: order…
kaizenCoder
  • 343
  • 2
  • 8
  • 22
5
votes
2 answers

Precedence of RewriteRules in .htaccess file on Apache Server

I have a number of RewriteRules in my .htaccess file. However, one specific rule is only executed if I remove another specific rule, regardless of how I order the two rules. Here's the rule which seems to have "lower" priority: RewriteRule…
LKM
  • 153
  • 1
  • 5
5
votes
1 answer

How to minimise effect of mischievous, persistent POST requests

For a few months now one of our shared hosting servers has been persistently and constantly hammered by "POST /" requests from what must be hundreds of thousands of individual IPs. On a number of occasions this has overwhelmed the server and led to…
5
votes
2 answers

ErrorDocument in .htaccess, is it possible to use relative path?

This doesn't work: ErrorDocument 401 ../../src/wrong_pwd.php it renders the path as text, it really prints ../../src/wrong_pwd.php and doesn't output the real file. If I put the absolute path it will render the contents of /var/www/home (I…
Andrea Ambu
  • 480
  • 1
  • 8
  • 13
5
votes
1 answer

Apache 2.4 with PHP-FPM .htaccess redirection

I have Apache 2.4 set up with PHP-FPM on a server. To pass from Apache to PHP-FPM I use the following: ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9001/hosting_files/site.com/admin_secure/$1 "admin_secure" is the DocumentRoot in the vhost. In…
nwalke
  • 643
  • 2
  • 12
  • 32
5
votes
3 answers

Is my webserver allowing pre-fetching?

I have an image based website that hosts multiple galleries. When a user clicks one of the images the views property for the particular image is incremented. However, I noticed when using Firefox (14.0.0.1) it increments the views twice, whereas…
Lee
  • 73
  • 7
5
votes
2 answers

Why doesn't my htaccess redirect work?

I have setup a simple htaccess redirect which looks like this (this is the whole .htaccess file): Options +FollowSymLinks RewriteEngine On Redirect 301 /something http://something.com/something.php If I then load the site which contains this…
willdanceforfun
  • 557
  • 2
  • 11
  • 23