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
4
votes
1 answer

How to prevent external direct-link to files with htaccess?

I have this in my htaccess at the public_html folder of my file server: RewriteEngine On RewriteBase / ReWriteCond %{REQUEST_URI} ^/files/* RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite.net/.*$ [NC] RewriteRule…
andreszs
  • 709
  • 1
  • 6
  • 16
4
votes
2 answers

Redirect depending on preferred language (Accept-Language) with .htaccess

When users request /, I want to redirect them to /en or /de, depending on their preference specified in the HTTP request header Accept-Language. I guess this is easy with server-side scripting, but I need a .htaccess solution as it has to work for a…
unor
  • 246
  • 2
  • 19
4
votes
1 answer

Can Apache .htaccess convert the percent-encoding in encoded URIs from Win-1252 to UTF-8?

I want to add a directive in my .htaccess, such that if the browser is pointed at a URI containing %E4 (ä) - or any other special character - the .htaccess automatically rewrites %E4 (ä) as %C3%A4 (ä). In summary, I want .htaccess to convert…
Rounin
  • 143
  • 7
4
votes
3 answers

nginx [emerg] unknown "0" variable

I've been trying for two days to convert an .htaccess to nginx rewrite the original file looked like this: # Turn on URL rewriting RewriteEngine On RewriteBase // # Protect hidden files from being viewed Order Deny,Allow Deny From…
Adrian
  • 67
  • 3
  • 8
4
votes
1 answer

htaccess password multiple password same user

How to assign multiple passwords to the same user in .htaccess password protection? It looks like this in my .pass file, but only the first one is working christina:o5hZ6Uplugq.2 christina:uaZOUG6BzJaUc
Zhenyu
  • 263
  • 1
  • 3
  • 10
4
votes
1 answer

How multiple sections work in Apache configuration (httpd.conf)?

For example, if my '/etc/apache2/httpd.conf' looks like this: AllowOverride None AllowOverride FileInfo The latter AllowOverride rule overrides its predecessor for the /home…
its_me
  • 225
  • 1
  • 7
  • 23
4
votes
2 answers

Enable Cross Origin Scripting on Nginx from retina.js to load files from another URL?

Im running a retina image plugin along with W3 Cache for CDN support. W3 cache moves images to S3, but the JS file won't server the files from there due to the difference in URL (it goes from h ttp://mysite.com to h ttp://assets.mysite.com) I found…
Danny Shepherd
  • 177
  • 1
  • 12
4
votes
2 answers

How to dynamically reload nginx config

I'm currently trying to setup Nginx for a domain with production, testing and development stages. Each comes with it's own partial Nginx config file with rewrites. The production and testing stages are set up as branches from a Git repository and…
Martijn
  • 356
  • 5
  • 13
4
votes
2 answers

using unicode in rewriterule

I have used the following statements in .htaccess file which contains utf8 characters in RewriteRule. .htaccess file is saved in notepad with utf8 encoding. All pages of site are saved in utf8 and charset of all is utf8.
4
votes
1 answer

htaccess rewriting all subdomains to subdirectories

I'm trying to build a catch-all for any subdomains (not captured by previous rewrite rules) for a certain domain, and serve a website from a subdirectory that resides in the same folder as the .htaccess file. I already have my vhosts.conf to send…
indorock
  • 141
  • 1
  • 2
4
votes
3 answers

.htaccess redirect umlaut domain

I am trying to redirect requests from a umlaut domain to another domain. My following code works with ANY other domain, but not umlaut: RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^(www\.)?frankfurter-flöhe\.de/$…
Christian Engel
4
votes
2 answers

Denying access to all files except index.html apache

Could someone help me with apache .htaccess file to deny access to all files and sub directories except for index.html on the documentroot for an apache server? I tried: Order deny,allow Order…
93196.93
  • 291
  • 1
  • 4
  • 13
4
votes
2 answers

Forwarding 80 to 443 on Nagios woes

I perhaps just need some extra insight because I don't see where I'm going wrong. I used an SSL Cert to secure our nagios server. We want to specifically require all traffic over nagios (like 2 users, lol) to use SSL. So I thought, oh, mod_rewrite +…
Ethabelle
  • 2,052
  • 14
  • 20
4
votes
2 answers

.htaccess - redirect non www to www and retain subdomains from redirecting

So, on my main domain 'domain.com' I created several subdomains from cPanel, like 'sub1.domain.com' and 'sub2.domain.com'. Their real location on server is in 'domain.com/sub1' and 'domain.com/sub2'. Now, I want to redirect non www to www with…
RhymeGuy
  • 201
  • 1
  • 2
  • 4
4
votes
2 answers

server-status not working if allowoverride is set to all

in my apache config i have following settings Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all
shorif2000
  • 351
  • 1
  • 8
  • 28