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.

2745 questions
78
votes
4 answers

How to get Apache2 to redirect to a subdirectory

I am running apache2 on Debian etch, with multiple virtual hosts. I want to redirect so that http://git.example.com goes to http://git.example.com/git/ Should be really simple, but Google isn't quite cutting it. I've tried the Redirect and Rewrite…
Hamish Downer
  • 9,142
  • 6
  • 36
  • 49
59
votes
4 answers

How to redirect root and only root via htaccess?

I want to redirect only my root to another url, but maintain all the /sub/directories where they belong (and redirect) example: mysite.com/1 redirects to somewhere mysite.com/admin opens a page i want mysite.com/ to redirect to mysecondsite.com and…
jardel
40
votes
2 answers

How do I get Apache2 to parse (without error) Header directives in a .htaccess?

I am getting pages loading with a 500 internal server error, due I believe to a directive that Apache has not been configured to allow. I have AllowOverride set to all, and a .htaccess file, including:
Christos Hayward
  • 1,152
  • 3
  • 15
  • 35
33
votes
1 answer

What is the name and location of the Nginx config file (htaccess equivalent)?

There are many tutorials on how to write Nginx rewrite rules to mimic Apache's .htaccess file but I can't confidently say I know what the name or location of this so-called Nginx config file actually is. I'm specifically looking for the Nginx config…
tim peterson
  • 683
  • 2
  • 9
  • 18
29
votes
4 answers

.htaccess is ignored even though VirtualHost has "AllowOverride All"

I'm running a LAMP server on Fedora 13 that's working fine; however, I just added an ".htaccess" file to my current site's docroot folder that is being completely ignored. I've tried half a dozen different tests, including this one: RewriteEngine…
Brian Lacy
  • 1,093
  • 4
  • 15
  • 23
23
votes
2 answers

How should I use the directive in .htaccess?

I'm trying to add a conditional statement using Apache's If directive in my .htaccess file. I have referenced this page http://httpd.apache.org/docs/trunk/mod/core.html#if but it doesn't elaborate much / give many examples. Two incomplete examples…
cwd
  • 2,693
  • 9
  • 32
  • 47
22
votes
3 answers

How to enable either Gzip or Deflate compression via .htaccess?

How to enable either Gzip or Deflate compression via .htaccess and which one is best these days? Code examples needed.
dzhi
  • 770
  • 3
  • 10
  • 23
20
votes
3 answers

Suspicious .htaccess File

This was uploaded to one of my FTP folders. I'm not familiar with Apache, but still curious - can someone tell me what type of dastardly act this file is trying to commit? Thanks! RewriteEngine On RewriteCond %{HTTP_REFERER} .*google.*$…
ovinophile
  • 303
  • 1
  • 4
19
votes
1 answer

How can I remove HTTP headers with .htaccess in Apache?

I have a website that is sending out "cache-control" and "pragma" HTTP headers for PHP requests. I'm not doing that in the code, so I'm assuming it's some kind of Apache configuration, as suggested by this question (you don't really need to go there…
Daniel Magliola
  • 1,402
  • 9
  • 20
  • 33
17
votes
3 answers

How to echo out from .htaccess?

We write a lot of code to htaccess but what is the best method to debug other than refreshing the page ? Is there some way that I can write it out to a file ? or is there some echo/print function ? Simply how do i know what my $1 $2 $3 is ?
Devrim
  • 1,197
  • 4
  • 16
  • 29
16
votes
2 answers

Break up a long line in a .htaccess file

I am setting a Content-Security-Policy header in my .htaccess file, and it has grown to be an extremely long single line, which is a bother to manage. Is there some way to break up this line into more manageable substrings? As a trivial example,…
MaxPRafferty
  • 273
  • 2
  • 6
15
votes
6 answers

to www or not to www

Possible Duplicate: What’s the point in having "www" in a URL? Should I use www in front of a URL or not? Some sites say we should and some say the opposite. Pros Cons If there is no www is in front of the URL, what should I put in my .htaccess…
marc-andre menard
15
votes
4 answers

IIS7: How to block access with a web.config file?

I know that IIS7 allows me to have a per directory configuration with the web.config xml file. I have a directory with some configuration files that don't want to be web accessible. A local web.config file forbidding read access to it would be a…
neves
  • 1,160
  • 2
  • 11
  • 16
14
votes
4 answers

Load time impact of htaccess

There are in general two possibilities of handling stuff on Apache: make configurations for folders one by one using htaccess file to fully resign htaccess and put all the rules into the httpd.conf Usage of htaccess is a load time issue. I want to…
Evgeniy
  • 255
  • 2
  • 10
1
2 3
99 100