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.

2829 questions
17
votes
4 answers

How to echo out from .htaccess?

We write a lot of code to htaccess but what is the best method to debug other than refreshing the page ? Is there some way that I can write it out to a file ? or is there some echo/print function ? Simply how do i know what my $1 $2 $3 is ?
Devrim
  • 1,187
4
votes
1 answer

Can .htaccess file read "variable" from external file?

I use a separate file software_version that is included using SSI into html files. So visitors can view current software version on download and some other pages. Also there is an URL to download the most current version of software: redirect…
4
votes
2 answers

How to use [OR] or substitute in an .htaccess file?

Summary The [OR] flag isn't working consistently across different servers. Details and question below. I have a website hosted on Godaddy and I wrote this code for an .htaccess file to redirect users to the https version of my site. It works…
DR01D
  • 350
  • 1
  • 3
  • 11
4
votes
1 answer

.htaccess commands are case insensitive?

I see the same .htaccess code snippet written with two different ways as follows: order allow,deny deny from all and Order Allow,Deny Deny from all I'm I right to assume both versions are…
IXN
  • 143
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
4
votes
1 answer

Preload Link using Files Directive in .htaccess

I'm currently preloading font files for one webpage on WordPress. So https://example.com not preloaded. https://example.com/test/ preloaded font file. This is what I've got in .htaccess. Header add Link ";…
3
votes
2 answers

Escaping chars in .htaccess

I can't find proper list (or you need to be registered to some sort of forum or not clear list) of which chars should be escaped in .htaccess file. I found that dots don't need to be escaped - but for me it's irracional because they have meaning in…
TheTanadu
  • 133
3
votes
2 answers

Allow, Deny or Require All in .htaccess for Different Apache Versions

When we want to block bots, spam referrers using .htaccess file, some websites use following code syntax: Order allow,deny Allow from all Deny from env=spambot But some websites tell that we need to use different codes for different Apache…
user433041
3
votes
3 answers

Does high traffic on HTACCESS affect the server?

i have a website and a sub domain.. the main website is hosted in server A and its sub domain in server B.. main website = server A sub domain = server B when i have high traffic i will redirect my main website to my sub…
3
votes
1 answer

Force HTTPS w/ Load Balancer and without (.htaccess rewrite)

I have the following code as a rewrite rule. RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L] This seems to work great with and without a ssl…
3
votes
1 answer

.htaccess file location

I am trying to use an .htaccess file to create clan URL for my website. I want to test it on my local version of the site and the upload to the server if I succeed. The question is, where do I have to put the .htaccess file? (I am using LAMP) Right…
ppp
  • 169
3
votes
2 answers

htaccess password protection error

I have an HTACCESS as follows: AuthUserFile /home/nasht00/.htmydomain AuthName "EnterPassword" AuthType Basic Require valid-user When I try it, the password pop-up appears. Whatever I enter in it, I get a 500 Internal Server Error. My password file…
nute
  • 801
3
votes
4 answers

Internal server 500 error

Hello Everyone I have created the following script in my .htaccess file Options +FollowSymlinks RewriteEngine on RewriteCond %{HTTP_HOST} domain.eu RewriteCond %{REQUEST_URI} !^domain RewriteRule ^(.*)$ domain/$1 [L] This script should redirect…
sanders
  • 103
3
votes
2 answers

.htaccess in upper directories being ignored

I have a .htaccess file in /var/www/html/htc directory with specific rules to bookmatic.net and another .htaccess file with general rules to all domains in /var/www/html When accesing bookmatic.net, the .htaccess file in /htc is running good, but…
2
votes
1 answer

HTACCESS: How to Add X-Robots-Tag to a Specific Directory?

I've tried to look for this answer here as well as Stackoverflow and could not find an applicable answer. I'm trying to add X-Robots-Tag 'noindex' to a specific directory on my website via HTACCESS. Purpose: I want to prevent all pages within this…
1
2 3
11 12