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

Proxy all requests for subdomain to an ip via htaccess/apache

Let's say I have the following subdomain with its own document root etc: monad2.mysite.com I want that all requests are proxied to an IP (for instance 193.159.3.129) but they must pass through the server at mysite.com (assuming monad2 is on this…
Christian
  • 466
  • 5
  • 23
5
votes
1 answer

Apache sends plain-text response when accessing SSL-enabled site without HTTPS

I've never encountered something such as this before. I was attempting to simply redirect the page to the HTTPS version if it determined that HTTPS was off, but instead it's displaying an HTML page rather than actually redirecting; and even odder,…
animuson
  • 279
  • 1
  • 6
  • 20
5
votes
1 answer

Why isn't htaccess following this php_value directive?

In .htaccess I've added php_value session.name "SID" This seems to have no effect, however, and no errors are thrown in error_log. Other rewrite rules in the same .htaccess file are working as expected. Why isn't htaccess following this php_value…
Isius
  • 284
  • 1
  • 4
  • 15
5
votes
1 answer

.htaccess rewrite http to https results in loop

On an apache 2.2 server running varnish, I am trying to redirect http -> to https for an entire Drupal Commons (http://commons.acquia.com/) site. Since varnish caches some redirects (R=301, but not R=302, I think), I first got my redirect working at…
Brian Wood
  • 161
  • 1
  • 3
5
votes
3 answers

Redirection by IP causing infinite loop

I am working to transfer a server from one box to another and do a massive code update tonight. To do this I'd like to set up a redirection so that normal site visitors go to a holding page. But developers and testers and the client go to the main…
Matt Rogers
  • 83
  • 1
  • 7
5
votes
4 answers

.htaccess file hacked, how to prevent this in future?

The hacker added a code in .htaccess file to redirect all search engine traffic to a malware website. I am now investigating this incident and trying to find out security loop holes. My situation is almost similar to this person's - .htaccess being…
Arpit Tambi
  • 481
  • 3
  • 5
  • 11
5
votes
4 answers

How to redirect non-www to www without hardcoding using .htaccess?

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] ...causes a perfect, non-hardcoding 301 redirect from "www to non-www", what would the exact opposite look…
Lizzy
5
votes
4 answers

How to set up a DNS to use a catch-all address?

This is not really a programming question, it's more about settings that I can alter visually. I have bought a domain and am wondering how I can get it work in such a way that everything before the .example.com except for things I've already set…
5
votes
1 answer

Error headers: ap_headers_output_filter() after putting cache header in htaccess file

Receiving error: [debug] mod_headers.c(663): headers: ap_headers_output_filter() after I included this within the .htaccess file: # 6 DAYS Header set Cache-Control "max-age=518400,…
Brad
  • 235
  • 1
  • 4
  • 8
5
votes
4 answers

Returning 404 code for unauthorized attempts

I have an admin directory on my web server (http://test.com/admin) and I don't want unauthorized parties to access this /admin/ directory instead I want to return 404 error code for all unauthorized accesses. My question is, is there any way to…
Willy
  • 225
  • 1
  • 5
  • 9
5
votes
1 answer

How to pass Question Mark (?) in password for HTTP Basic Authentication in URL parameters?

I am automating a website which requires HTTP Basic Authentication. The suggestions given in this link work like a charm in most cases: Can you pass user/pass for HTTP Basic Authentication in URL parameters? However, some of the users have a…
4
votes
1 answer

Block IPv6 addresses in my .htaccess file but I get 500 Internal Server Error?

I want to block all IP Addresses starting like this 2a01:598:xxx in my .htaccess file on my WordPress website. But everytime I edit my .htaccess file I can't visit my website anymore. I get an Internal Server Error. And the end of my .htaccess file…
Benjamin S
  • 51
  • 3
4
votes
1 answer

Docker httpd & htaccess - Could not open password file

I have an error that I can't resolve, even with my last researches. Folder structure: -rw-r--r-- 1 root root 105 Aug 8 15:58 Dockerfile -rw-r--r-- 1 root root 21371 Aug 8 16:05 my-httpd.conf drwxr-xr-x 2 root root 4096 Aug 8 15:37 www 1 - I…
Quentin Rey
  • 63
  • 2
  • 8
4
votes
4 answers

Almost empty .htaccess file causing 500 error response

I created a test directory called "rewrite" and put a .htaccess file inside with a rewrite rule. When I go to that URL through my browser I get a 500 Internal Server Error. So I thought it was my rewrite syntax and tried a few changes, same thing.…
Anthony
  • 315
  • 4
  • 15
4
votes
1 answer

AddType application/x-httpd-php .html stopped working

I have the following line in .htaccess AddType application/x-httpd-php .html .htm And it used to work for years to treat html pages as php, however recently I noticed it is not working anymore, except only in the homepage (example.com), and not…
Mike
  • 143
  • 1
  • 1
  • 3