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
1
vote
2 answers

Deny all "direct" traffic

My server is under heavy attack (maybe DDOS, I've no idea). I've checked the access logs (to put things into perspective, it's site with a daily 1000 visitors, nothing fancy): 78.176.175.208 - - [14/Dec/2010:17:11:37 -0800] "GET /XXX.com/ HTTP/1.1"…
elma
  • 45
  • 1
  • 3
1
vote
2 answers

Rewrite Rule in .htaccess

I asked this question in Stackoverflow but one of the respondents told me to ask it in here instead. I wonder if this is something that can be done in htaccess? I have this URL: https://www.example.com/folder/New.jsp?par=new1 ...which I want to…
liza
  • 11
  • 2
1
vote
1 answer

Conditional Mod-Rewrite for setting Root Directory ( apache htaccess )

am trying to write a redirect but as a green noob is tougher than i tought. What i want is: on the condition that there are No Specific Page in the url, but the language IS set, it to redirect to the home page of that language. First ill tell you…
Sam
  • 423
  • 3
  • 7
  • 23
1
vote
1 answer

Help with variables in htaccess

redirect http://anySubdomain(wildcard).mydomain.com/ to: anysubdomain(wildcard).mydomain.com/page2.php i tried with this: RewriteCond %{HTTP_HOST} ^(.*)\.mydomain.com$ [OR] RewriteRule ^/?$ "http\:\/\/$1\.mydomain\.com\/page2\.php"…
John
  • 21
  • 1
  • 2
1
vote
2 answers

Apache isn't deflating my website home page

I have the following 3 rules at /.htaccess AddOutputFilterByType DEFLATE text/html text/plain text/css application/json AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript AddOutputFilterByType DEFLATE…
João Dias
  • 41
  • 6
1
vote
2 answers

Making the output of +Indexes match a rewritten URL

I'm using mod_rewrite to map /foo/bar/baz to /foo/qux using RewriteEngine on RewriteBase /foo/ RewriteRule ^bar/baz$ bar/baz/ [L,R=permanent] RewriteRule ^bar/baz/(.*) qux/$1 [L] I want to allow indexes in /foo/qux, so I have Options +Indexes in…
Chris Conway
  • 111
  • 3
1
vote
1 answer

Virtual Directory Path in HTML Files

I tried to create a development server by copying a website from one host to a second different host, but the servers seem to handle virtual paths differently. On the main server this works:
JMC
  • 506
  • 6
  • 23
1
vote
1 answer

Hacked WordPress blog

My WordPress Blog is under constant attack with this URL /page/2/?pretty;board=Themes%253btopic%3Ddefault.0 I tried to defend with # BEGIN RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI}…
1
vote
1 answer

Regular expression not working in .htaccess

I'm trying to limit which characters can be used in the request URI using: RewriteEngine on RewriteCond %{REQUEST_URI} !^([a-z0-9:/\.\_\-]) [NC] RewriteRule ^.* - [F,L] For some reason it's not working. Any ideas? Thanks!
Zero
  • 55
  • 5
1
vote
1 answer

Difference between SetEnvIf and RewriteCond?

In my .htaccess file, I'm currently using RewriteCond to match the user agent of bad bots. I know that SetEnvIf can also be used to block bad bots too. The question is, what's the difference between RewriteCond and SetEnvIf? Is one better than the…
Zero
  • 55
  • 5
1
vote
1 answer

.htaccess files are no longer working

For some reason, .htaccess files have stopped working all of a sudden. I checked apache2ctl -t -D DUMP_MODULES and rewrite_module is indeed loaded. However, putting random garbage in an .htaccess file is not causing any errors to show up in…
Nathan Osman
  • 2,725
  • 7
  • 32
  • 46
1
vote
1 answer

Apache .htaccess set base for absolute path

When I test a website in my local installation of Apache I always have /mysite.com/ as the path. When the site gets deployed the root path will be just /. Because I need to use absolute referencing I have to use /mysite.com/files on…
Francisc
  • 153
  • 1
  • 3
  • 11
1
vote
2 answers

RewriteCond in .htaccess file gives me bad flag delimiters

I'm upgrading a website and I use this .htaccess file to show maintenance page: #MAINTENANCE-PAGE REDIRECT RewriteEngine on RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 # Bogus IP address for posting here RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.0 #…
Steven
  • 275
  • 2
  • 9
  • 21
1
vote
4 answers

Help! Why do blocked bots still waste bandwidth?

I've blocked a majority of bots that keep sending POST requests to my website, using .htaccess. Each time one of these bots tries to access my website it receives a 403 forbidden error message. My question is, why is my bandwidth usage still…
Zero
  • 55
  • 5
1
vote
2 answers

Apache error log; Php error file does not exist; Think it has something to do with mod_rewrite

I get a whole bunch of these errors, but with different ad id:s in the end. The one below has ad id "Bmw_m3_brand_new_2939822" [Fri Oct 29 22:57:37 2010] [error] [client 111.111.11.11] File does not exist: /var/www/annons, referer:…
Anonymous12345
  • 1,022
  • 2
  • 13
  • 18