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
6
votes
3 answers

Using Apache htaccess file to change URL to lowercase

How can I modify my .htaccess file on Apache to do the following: "If the URL ends in .aspx, rewrite the entire URL to lowercase." Backstory: I recently migrated a website from ASPX hosting to Linux/Apache hosting. There are some old URLs in the…
DWRoelands
  • 4,878
  • 4
  • 29
  • 42
6
votes
3 answers

moodle data root location not secure error

I read moodles documentation where it says that if the data root directory has to be in the site's public html folder ( Please see that i can not create it outside it since i dont have sufficient privileges as i am using a free account ). then you…
Harshit Laddha
  • 2,044
  • 8
  • 34
  • 64
6
votes
4 answers

Emberjs application refresh on route other than index gives 404 error

I have a small ember application using the starter kit provided by Ember-App-Kit(EAK). I have uploaded the dist dir after building for production to AWS EC2 instance. Issues that I am facing as of now:: When I hit the root url, I can see the…
6
votes
2 answers

Adding Expires Headers and .htaccess

I'm trying to optimise a WordPress site of mine - Type & Music based on reports I've been getting from GTmetrix. One of the things I'm being advised to do is add expires headers and leverage browser caching. I may be wrong, but I assume these are…
lateralaus
  • 1,523
  • 3
  • 11
  • 11
6
votes
2 answers

.htaccess deny access from external request

I want to limit the access for some pages in my web site. I have some BL pages in PHP and I want to limit thier access to only internal access. I mean that I want that these pages will be denied if the user type them in the browser, but will be…
nrofis
  • 8,975
  • 14
  • 58
  • 113
6
votes
2 answers

What's wrong with my RewriteRule via .htaccess? (Why does it need RewriteBase?)

rewriteengine on rewriterule ^/a/b$ ^/c$ not working,but rewriteengine on rewritebase / rewriterule ^a/b$ ^c$ works.
user198729
  • 61,774
  • 108
  • 250
  • 348
6
votes
4 answers

Where to find .htaccess file in my Xampp localhost

I have a simple problem here. I'm a beginner in using php and apache. Actually I want to modify some config in my .htaccess but i cant find in. Can anyone tell me where is it located. TIA.
user3213861
  • 125
  • 1
  • 2
  • 10
6
votes
1 answer

Create subdomain from a folder, but deny folder access

Okay, I've spent almost 4 hours searching the site for a solution, and another 2 hours searching google, wich is not quite useful when most sites copy paste the data. So here I decided to ask for a little help. I created a subdomain successfully,…
user3153340
  • 189
  • 1
  • 9
6
votes
2 answers

Configure the PHP built-in web server

While using the built-in PHP web server, how do you set configuration options, typically set using php.ini or a .htaccess file?
Jonathan
  • 18,229
  • 10
  • 57
  • 56
6
votes
0 answers

Accessing File Modified Date in .htaccess

Is it possible to get access to file attributes such as when a file was created or last modified? I have cached gzip files, and would like to be able to set a last-modified header to them. Something like:
Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48
6
votes
1 answer

how can i access custom headers from an htaccess file?

I am currently using HA proxy in front of an apache setup. Since HA proxy is doing the https termination, i can't use apache to tell if it's https or http. So I got HA proxy to add a custom header to send to apache (X-Forwarded-Proto = http or…
DAB
  • 1,303
  • 14
  • 23
6
votes
1 answer

Let .htaccess RewriteRule redirect to a script "in current dir" (instead of an explicit path)

I'm using a RewriteRule in .htaccess to redirect anything that is not an existing file, to a "cms.php" file which dynamically handles any request (or outputs some error message if appropriate). Here's what I do in .htaccess: RewriteEngine…
Sheldon Pinkman
  • 1,086
  • 4
  • 15
  • 21
6
votes
1 answer

Web.config redirect all paths to index.php - not working

I predominantly work with Apache and .htaccess, but I am currently working on a site that is hosted on a Windows server. The Web.config is causing me a lot of problems. I am trying to redirect all the URL requests to the index.php so that the PHP…
Adam
  • 209
  • 3
  • 14
6
votes
5 answers

Block user IP's with .htaccess or PHP?

From a performance only view, which would be the best way to block 30 IP addresses? A) .htaccess file or B) PHP code in the file
JasonDavis
  • 48,204
  • 100
  • 318
  • 537
6
votes
1 answer

What's $0 in nginx? (mod_rewrite)

I'm trying convert my Apache rewrite rules for my new nginx webserver, but I'm having problems translating this particular line: RewriteRule ^(arin|barry|john|ross|danny).*$ /share/$0 [NC] As for my old Apache server, this rule…
Chiru
  • 3,661
  • 1
  • 20
  • 30
1 2 3
99
100