Questions tagged [.htaccess]

Directory-level configuration file used by Apache web servers. Use this tag if and only if .htaccess content is directly involved in the topic. We know many people are using .htaccess, but kindly ask the members of the community to not use this tag, unless you know it is on-topic in your question. Also notice what the [tag:apache] tag has to say about questions about _configuring_ Apache httpd and their potential off-topicness on Stack Overflow

The .htaccess (hypertext access) file is a configuration file for the Apache web server, allowing configuration settings to be made at a directory-specific level. It overrides the server-wide or site-level settings in the main Apache server-level configuration but must be enabled in the server-level configuration to work.

Most (though not all) directory-specific Apache settings can be configured in .htaccess. One of the most common usages for it is URL redirection using mod_rewrite, which is used by many sites for SEO purposes and to provide easier-to-read URLs. The Apache documentation has further information about mod_rewrite as well as simpler solutions for many common use cases.

.htaccess files are also commonly used to define custom error pages (e.g. for 404 errors). They can also be used for specifying directory-specific security and user authentication, configuring the PHP installation, file handlers and MIME types, output compression, and more.

For more information on .htaccess files and how to use them, see the Apache documentation.

More information

Top Questions for reference

  1. Tips for debugging .htaccess rewrite rules
  2. Access-Control-Allow-Origin Multiple Origin Domains?
  3. How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess
  4. How does RewriteBase work in .htaccess
  5. htaccess redirect to https://www
  6. How to redirect all HTTP requests to HTTPS using .htaccess rules?
  7. Hidden features of mod_rewrite
  8. .htaccess redirect all pages to the homepage on a new domain
  9. Create subdomains on the fly with .htaccess (PHP)
  10. .htaccess mod_rewrite - how to exclude directory from rewrite rule
  11. Leverage browser caching for 3rd party JS

How to ask

  • Make sure you explain how .htaccess is involved in your question
  • Explain the expected behavior, the actual behavior and the difference between the two
  • Show the relevant part of the .htaccess
72915 questions
154
votes
9 answers

Apache: client denied by server configuration

I am getting [Tue Apr 24 12:12:55 2012] [error] [client 127.0.0.1] client denied by server configuration: /labs/Projects/Nebula/bin/ My directory structure looks like (I am using Symfony 2, should be similar structure for other web frameworks) I…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
149
votes
14 answers

.htaccess redirect http to https

I have an old url (www1.test.net) and I would like to redirect it to https://www1.test.net I have implemented and installed our SSL certificate on my site. This is my old file .htaccess: RewriteEngine On RewriteRule !\.(js|gif|jpg|png|css|txt)$…
Bàn Chân Trần
  • 1,890
  • 2
  • 21
  • 24
143
votes
8 answers

deny direct access to a folder and file by htaccess

Here is the scenario: There is a index.php file in root folder some files are included in index.php which are in the includes folder. 1 other file (submit.php) is in the root folder for form submit action. I want to restrict direct user access to…
Imrul.H
  • 5,760
  • 14
  • 55
  • 88
143
votes
6 answers

How to deny access to a file in .htaccess

I have the following .htaccess file: RewriteEngine On RewriteBase / # Protect the htaccess file Order Allow,Deny Deny from all # Protect log.txt Order Allow,Deny Deny from all #…
Timothée HENRY
  • 14,294
  • 21
  • 96
  • 136
137
votes
9 answers

deny directory listing with htaccess

I have a folder, for example : /public_html/Davood/ and too many sub folder in folder, for example : /public_html/Davood/Test1/ , /public_html/Davood/Test1/Test/ , /public_html/Davood/Test2/ , ... I want add a htaccess file into /public_html/Davood/…
DJafari
  • 12,955
  • 8
  • 43
  • 65
134
votes
19 answers

How to check whether mod_rewrite is enable on server?

Currently I am using the hosting with lightspeed server. Hosting says mod_rewrite is enabled but I can't get my script working there. Whenever I try to access the URL, it returns 404 - not found page. I put the same codes at another server which is…
knightrider
  • 2,533
  • 7
  • 30
  • 42
133
votes
18 answers

Remove .php extension with .htaccess

Yes, I've read the Apache manual and searched here. For some reason I simply cannot get this to work. The closest I've come is having it remove the extension, but it points back to the root directory. I want this to just work in the directory that…
Dirty Bird Design
  • 5,333
  • 13
  • 64
  • 121
127
votes
34 answers

Getting a 500 Internal Server Error (require() failed opening required path) on Laravel 5+ Ubuntu 14.04

I have installed Laravel many times on Windows OS but never had this problem. However, on Ubuntu 14.04 I am getting a 500 Internal Server Error, and messages like this in my logs: [Wed Jul 22 10:20:19.569063 2015] [:error] [pid 1376] [client…
DpEN
  • 4,216
  • 3
  • 17
  • 26
126
votes
9 answers

How to debug .htaccess RewriteRule not working

I have a RewriteRule in a .htaccess file that isn't doing anything. How do I troubleshoot this? How can I verify if the .htaccess file is even being read and obeyed by Apache? Can I write an echo "it is working" message, if I do write it, where…
macha
  • 7,337
  • 19
  • 62
  • 84
126
votes
9 answers

Create subdomains on the fly with .htaccess (PHP)

I am looking to create a system which on signup will create a subdomain on my website for the users account area. e.g. johndoe.website.example I think it would be something to do with the .htaccess file and possibly redirecting to another location…
Ben McRae
  • 3,551
  • 13
  • 36
  • 31
119
votes
5 answers

Enabling error display in PHP via htaccess only

I am testing a website online. Right now, the errors are not being displayed (but I know they exist). I have access to only the .htaccess file. How do I make all errors to display using my .htaccess file? I added these lines to my .htaccess…
Ogugua Belonwu
  • 2,111
  • 6
  • 28
  • 45
118
votes
15 answers

Server unable to read htaccess file, denying access to be safe

I have created a simple app using AngularJS. When I tried to host that project in my website http://demo.gaurabdahal.com/recipefinder it shows the following error: Forbidden You don't have permission to access /recipefinder on this server. Server…
Saurab
  • 1,931
  • 5
  • 20
  • 33
118
votes
8 answers

Hidden features of mod_rewrite

There seem to be a decent number of mod_rewrite threads floating around lately with a bit of confusion over how certain aspects of it work. As a result I've compiled a few notes on common functionality, and perhaps a few annoying nuances. What other…
Owen
  • 82,995
  • 21
  • 120
  • 115
113
votes
9 answers

How to use a RELATIVE path with AuthUserFile in htaccess?

I have a .htaccess that uses basic authentication. It seems the path to the .htpasswd file isn't relative to the htaccess file, but instead to the server config. So even though I have the .htaccess and .htpasswd files in the same directory, this…
DssTrainer
  • 1,439
  • 3
  • 12
  • 15
112
votes
8 answers

.htaccess - how to force "www." in a generic way?

This will change domain.example to www.domain.example: # Force the "www." RewriteCond %{HTTP_HOST} !^www\.domain\.example$ [NC] RewriteRule ^(.*)$ `http://www.domain.example/$1` [R=301,L] How do I replace the "domain" part so that this works on any…
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441