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

.htaccess per directory in nginx

I am new to nginx and I have been on apache before. In apache, each directory can have a .htaccess to target the directory and and it's subdirectories. Is this possible for nginx? If so, how do I do that? Thank you very much!
ambiguousmouse
  • 293
  • 1
  • 3
  • 7
7
votes
2 answers

Can I password protect a location (not directory) in apache using htaccess?

I have used code like this in apache configuration to protect locations with password AuthType Basic AuthName "Protected Area" AuthUserFile /home/user/public_html/.htpasswd Require valid-user is…
dimvic
  • 231
  • 2
  • 7
7
votes
3 answers

In Apache does the .htaccess file override the httpd.conf for mod_rewrites?

In my Apache httpd.conf file I have this declaration inside a VirtualHost tag. RewriteEngine On RewriteCond %{HTTP_HOST} !^www.shanestillwell.com$ [NC] RewriteRule ^(.*)$ http://www.shanestillwell.com/$1 [L,R=301] And this inside my…
Shane Stillwell
  • 337
  • 1
  • 4
  • 11
7
votes
2 answers

Do I need to restart Apache if I modified an htaccess file?

So I changed an htaccess file on my server, and am not seeing the changes. Do I need to restart Apache if I modified an htaccess file? Update: So I don't think this is my problem. Please see my related question: Why is my htaccess file preventing…
Andrew
  • 3,453
  • 9
  • 33
  • 36
7
votes
5 answers

How do I use .htaccess to always redirect from HTTP to HTTPS?

There's a few similar questions which I tried to work out the answer from, but so far I have been unsuccessful. Please advise how I can always redirect http to https (and also remove www. from the hostname in the process). Also a side note, it would…
Nick Bolton
  • 5,126
  • 12
  • 54
  • 62
6
votes
1 answer

Whitelist an Individual's IPv6 Range via .htaccess

I have a section on a website that blocks access to all IPs, except for those that are whitelisted. For IPv4, this is very simple, because even with dynamic IPs, they generally won't changed for months, or even years. However, with IPv6, these seem…
IPv6Quest
  • 63
  • 1
  • 4
6
votes
3 answers

Enable PHP extension within .htaccess

Does anyone know how to enable a PHP extension within the .htaccess file? Possibly: (.htaccess file) php_value extension=php_soap.so
Torez
  • 161
  • 1
  • 1
  • 3
6
votes
2 answers

Redirect all urls to the root except /wp-admin and wp-json

I try to redirect all urls to the root except for the wordpress administration and the wordpress REST API. I have these rules in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond…
Quentin Brosse
  • 63
  • 1
  • 1
  • 4
6
votes
1 answer

Require all denied has no effect. Require all allowed, works

I have a website structure setup as follows, which I am trying to organize access levels for each but without specifying as that requires the structure to be fixed (aka, if i copy this to a different site, into a subfolder, it would…
Kraang Prime
  • 215
  • 1
  • 2
  • 11
6
votes
0 answers

How do I allow users to override X-Frame-Options when using Apache + PHP-FPM?

I have an Ubuntu 14.04 server running Apache + PHP-FPM + FastCGI, serving user home pages. For security, I have enabled in Apache's configuration: Header set X-Content-Type-Options: "nosniff" Header set X-Frame-Options: "sameorigin" Header set…
muru
  • 589
  • 8
  • 26
6
votes
1 answer

how to sort apache directory listing in last modified order

# SET DISPLAY ORDER IndexOrderDefault Descending Name the above value is used to sort directory listing in decending name value how can i create the similiar results for sorting the directory in last modified order.i am using .htaccess.please don't…
sukhjit dhot
  • 183
  • 1
  • 1
  • 4
6
votes
4 answers

Apache SetEnvIf failing to match Request_Uri

Simple condition, which never match and set variable: SetEnvIf Request_URI "^/path/to/something*" access_granted Checking URI by using PHP is giving correct string, however variable is never set. echo getenv('Request_URI'); -->…
Ivan
  • 195
  • 1
  • 2
  • 8
6
votes
3 answers

Creating a cookie-free domain to serve static content

I am trying to create a "example.com" domain to serve static content to my original domain. How would I make the "example.com" domain to so its cookie-free when loading content? I am thinking that this should be done using a htaccess file but not…
pawelglow
  • 163
  • 1
  • 1
  • 4
6
votes
5 answers

Redirect all http AND https non-www URLS to https://www.example.com via htaccess

For reasons much too long and complex to get into (it involves several layers of corporate red tape resulting in someone else not purchasing a wildcard SSL certificate I requested), I have to set up a domain to redirect all requests to…
Scott
  • 163
  • 1
  • 1
  • 6
6
votes
0 answers

Is it possible to reference environment variables from a php_value statement in .htaccess?

I am trying to access an environment variable in a php_value statement within an .htaccess file. Here's a couple example usages: php_value include_path ".:/usr/lib/php:[b]%{My_Environment_Variable}[/b]" or php_value auto_prepend_file…
Non Ba
  • 61
  • 2