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
13
votes
2 answers

Configuring favicon with expires header in htaccess

I have implemented Expires headers via mod_expires on my Apache server and have successfully created expires headers for most file types, however I am having trouble with the favicon. I initially tried adding a set of instructions for the .ico files…
thehuby
13
votes
1 answer

Either all Options must start with + or -, or no Option may

I have this line in a .htaccess file Options +SymLinksIfOwnerMatch ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch ExecCGI Includes…
d0001
  • 329
  • 1
  • 3
  • 7
13
votes
4 answers

.htaccess RewriteCond for REMOTE_ADDR while behind Load Balancer?

I have a web server behind a load-balancer. I need to add a conditional redirect to my .htaccess in order to display a maintenance page whenever we take the site offline for maintenance. This part is straightforward: RewriteEngine on RewriteCond…
Jake Wilson
  • 8,814
  • 29
  • 97
  • 125
13
votes
5 answers

Does it matter in which order rules are placed in htaccess?

I hope this is a simple YES or NO answer (please specify why) Q1: Does it matter in which order rules are placed in htaccess? Especially when they are completely separated items. Q2: If yes, am I applying the right order? I want to to speed up the…
Sam
  • 423
  • 3
  • 7
  • 23
12
votes
1 answer

What is the difference between HTTP_HOST and HTTPS_HOST in apache .htaccess files?

I'm editing an .htaccess file.. In RewriteCondition for RewriteRules, HTTPS_HOST seems to only match urls that are accessed via https:// protocol (ssl). I saw in docs somewhere that it's a T/F variable that indicates if the url was accessed using…
SherylHohman
  • 405
  • 1
  • 5
  • 15
12
votes
5 answers

How to solve "ExpiresActive not allowed here" error message in .htaccess file?

I am trying to add Expires headers to the HTTP responses of the site I am working on. The only way for me to control the Apache 1.3 server is by editing my .htaccess file. I tried adding code such as the following to enable the Expires…
Daan
  • 223
  • 1
  • 2
  • 7
12
votes
2 answers

SSL redirect on EC2 instance behind SSL terminating load balancer

I'm trying to redirect all url's to https in a web application. I have an ec2 instance behind an elastic load balancer. SSL is terminated on the load balancer. Any attempts at redirection end up giving me the familiar 'this page is requesting in…
rix
  • 277
  • 4
  • 10
12
votes
3 answers

Convert and redirect URL in uppercase to lowercase using .htaccess

I would like to redirect a URL with uppercase characters http://localhost/A/B to a lowercase version http://localhost/a/b using the .htaccess file. Using regex I can capture A and B but is it possible to convert them to lowercase?
tintin
  • 445
  • 2
  • 6
  • 12
12
votes
1 answer

max length of url 257 characters for mod_rewrite?

My url scheme is /foo/var1-var2-var3.../bar I am using these mod_rewrite rules: RewriteBase /foo/ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [PT,L] If the length of the string…
Daniel
  • 125
  • 1
  • 1
  • 6
12
votes
3 answers

How can I redirect an entire site to a single page?

I'm in the process of shutting down a site, and have replaced the old site with a single "nobody home" page at the root level of the site. Now I need to set up some redirection, so that any request to any part of the site, no matter how complicated,…
Jim Miller
  • 713
  • 2
  • 11
  • 23
11
votes
2 answers

Apache .htaccess error: 'not allowed here' on Debian Wheezy

I am trying to configure an apache virtualhost which needs to be password protected in the root directory. So I created a .htpasswd file (with sha passwords) and configured the .htaccess file. Howevery whatever I do, on the webpage I get an error…
BonifatiusK
  • 243
  • 1
  • 4
  • 12
11
votes
1 answer

Increase the value of LimitRequestFieldSize in Apache

I have developed an application which uses a jQuery plugin, which in turn uses excessive cookie data. The problem is, after every 15-20 request I am shown this error message by the browser: Your browser sent a request that this server could not…
10
votes
1 answer

Exclusion of a protected sub-url does not work on Apache 2.4?

I try to exclude a sub-url "/shop/api" from my protected website. It worked fine on different server on Apache/2.2.15 but now not with Apache/2.4.7? It always asks for the basic authentication. Any Idea what I did wrong? AuthType Basic AuthName…
megloff
  • 403
  • 4
  • 11
10
votes
3 answers

How to redirect from HTTPS to HTTP before server error?

I used to operate a website with an SSL certificate, but have stopped using the SSL certificate. The problem is that most of the external links to the website use the https:// prefix. I have tried the https:// to http:// redirect in the .htaccess…
user981178
  • 445
  • 1
  • 3
  • 13
10
votes
4 answers

.htaccess does not ask the password

I am using Ubuntu 12.04 and trying to use .htaccess on a page with apache2 server on it. My .htaccess file looks like this: AuthType Basic AuthName "Password Required" AuthBasicProvider file AuthUserFile /home/janeb/.htpasswd require…
Sarp Kaya
  • 377
  • 2
  • 3
  • 12