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
8
votes
5 answers

Relative substitution in mod_rewrite RewriteRule

I want to create a mod_rewrite RewriteRule which is independent from the location where the web page is installed. I want to define the rewrite rule in a .htaccess file. Let's take this as an example: RewriteEngine on RewriteRule ^(.*)\.html…
kayahr
  • 313
  • 4
  • 14
8
votes
5 answers

How can I perform a syntax check on an .htaccess file in a shared hosting environment?

I have a build script (Perl) that modifies the .htaccess file when I deploy my applications. As a double-check, I'd like to be able to perform some sort of syntax checking on the created .htaccess file. I am familiar with the idea of using apachectl…
Danny
  • 311
  • 1
  • 4
  • 10
8
votes
2 answers

Is there a limit for .htaccess?

Hey all. I was just wondering if there's a limit for the .htaccess file for Apache 2. I'm working on a caching plugin and thaught that it might be a good idea to use the .htaccess file to point to generated static html files. So, anybody ever tried…
kovshenin
  • 11
  • 2
  • 6
8
votes
1 answer

.htaccess Redirect 301 with trailing slash adds trailing slash to destination

Just had my website re-done and am trying to set up redirects in the .htaccess file for links that have changed This works fine, except it doesn't work for /example/ (with trailing slash on source path) Redirect 301 /example /example.php So I added…
Chris Dutrow
  • 734
  • 8
  • 20
7
votes
2 answers

Apache 2.4 authenticate anonymous users but allow others by IP

I am trying to configure Apache to allow users from a selection of IPs access to a Flask application without authentication, but to challenge any other users for credentials. As things stand I have the following configuration:
btongeorge
  • 277
  • 1
  • 11
7
votes
2 answers

What does do in .htaccess?

ExpiresActive On ExpiresByType application/javascript "access 1 week" ExpiresByType text/css "access 1 week" I use a lot of these in my .htaccess files to set caching, deflate, Accept-encoding…
twharmon
  • 181
  • 1
  • 1
  • 6
7
votes
5 answers

How to block IP in .htaccess on Apache 2.4

I've upgraded Apache 2.4 and would like to block an Ip this could be done by using the following in the .htaccess on Apache 2.2 Order Deny,Allow Deny from 50.62.136.183 However how can I achieve the same in the .htaccess on Apache 2.4
Oudin
  • 341
  • 2
  • 5
  • 10
7
votes
2 answers

Vanity URL manager for Apache Web Server

I'm looking for a tool that manages vanity url's for a single domain running on Apache (or IHS - IBM HTTP Server). What i mean by vanity URL: www.mycompany.com/ProjectA would redirect to servera.mycompany.com/whatever www.mycompany.com/ProjectB …
Roy Rico
  • 612
  • 2
  • 9
  • 20
7
votes
5 answers

Apache Redirect folder to subdomain

A client had an application at www.example.com/dir. They have now set up a subdomain at dir.example.com. The subdomain references the files stored at www.example.com/dir. They'd now like people accessing www.example.com/dir to be redirected to…
Thody
  • 183
  • 3
  • 3
  • 5
7
votes
1 answer

Why is allow not allowed here in apache2

I've the following in my httpd.conf file: Options Indexes FollowSymLinks AllowOverride AuthConfig FileInfo Options=Indexes,Limit Order allow,deny Allow from all Next, I've a directory ChatLogs located…
hjpotter92
  • 670
  • 1
  • 10
  • 20
7
votes
2 answers

Apache server-status returning 404, then redirecting to my Wordpress install

I'm trying to get Munin's various Apachie plugins to work on my web server, but I'm hitting issues. Upon asking Munin to check available plugins, two of the three Apache plugins return an error saying that apache server-status cannot be…
Oliver Haslam
  • 135
  • 1
  • 1
  • 9
7
votes
1 answer

Apache deflates .xml.gz files

I noticed an error in google webmaster tools regarding a gzipped version of a sitemap. Turns out the sitemap.xml.gz file is gzipped twice: one upon creation (as it should be) and another time when being served. The .htaccess file has this…
Matteo Riva
  • 297
  • 3
  • 14
7
votes
2 answers

Bypassing htaccess restrictions?

I found this in my apache access logs access.log:555.555.555.555 - - [05/May/2011:12:12:21 -0400] "GET /somedir/ HTTP/1.1" 403 291 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0" access.log:555.555.555.555 - -…
Hrvoje Špoljar
  • 5,245
  • 26
  • 42
7
votes
2 answers

IIS Basic Authorization ala .htaccess/.htpasswd in apache

How do I implement the protection of the pages (asp.net mvc app), so when I hit the home page or any other pages within the application I get a login dialog popup in the browser I'm looking for something similar to what Apache .htaccess and…
7
votes
4 answers

How to throw a 404 error from htaccess?

Everything I find seems to be about created a custom 404 page. That is not what I am trying to do. If I want to block access to a page I can do this in htaccess: RewriteRule pattern - [F] However, "Forbidden" hints that the page does exists. I…
JD Isaacks
  • 895
  • 5
  • 14
  • 25