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

.htaccess redirect all extension to php

I recently updated my .htaccess file to hide the .php extension of the urls. It works nice, when I try to reach domain.com/index, it displays the php file. When I type domain.com/index.php it redirects me to the domain.com/index url and displays the…
jameson
  • 61
  • 1
  • 2
6
votes
1 answer

Unable to set php_value in .htaccess file

I am trying to set up NewRelic on my Apache2/PHP server, and have it report different applications per vhost. To do this, the php value newrelic.appname must be changed. It is defined by default in /etc/php.d/newrelic.ini however to do per vhost…
doublesharp
  • 217
  • 1
  • 3
  • 12
6
votes
9 answers

Successfully, permanently ban a user from a website?

I have a social networking website and I want to ban a user from the website. I've added his IP address to the ban list in the .htacess file and to the php level for banning that user, but he keeps coming back with different IPs. How can I…
mahen3d
  • 4,342
  • 14
  • 36
  • 57
6
votes
1 answer

When does Apache re-read the updates to .htaccess files?

I have a hosted server. When I update .htaccess, are the updated rules immediately in effect? I understand that hosters can do what they want, and it's impossible to know without knowing the particular policy of this particular hoster. But in the…
Cheeso
  • 572
  • 3
  • 18
6
votes
3 answers

How can I password prompt certain IPs and allow all others free access using Apache?

SOLVED: The idea is that if the visitor comes from China they have to pass a basic authentication. If you have any other IP address you can visit the site without being hassled (including proxies) //1400 rules.... SetEnvIf Remote_Addr…
Moak
  • 734
  • 3
  • 10
  • 31
6
votes
2 answers

Why would an .htaccess file result in 403 Forbidden when the only line is "Allow from all"?

I'm running a server: Apache/2.2.8 (Ubuntu) mod_ssl/2.2.8 OpenSSL/0.9.8g Without a .htaccess file, everyone can access the web content. However, I add a .htaccess file with the following content: Allow from all ... and everyone gets 403 Forbidden…
hughes
  • 161
  • 1
  • 1
  • 4
6
votes
2 answers

How do you redirect URLs with a query string to another host?

This htaccess snippet is supposed to redirect myhost.com/?p=1&preview=true to alt.myhost.com/?p=1&preview=true RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^myhost.com$ [NC] RewriteRule ^/\?p=([0-9]+)&preview=true$…
qodeninja
  • 2,753
  • 10
  • 32
  • 33
6
votes
2 answers

Only allow GET request with htaccess?

How should I allow only GET request to access all the files and script from my server using htaccess? My web server is Apache
DucDigital
  • 1,491
  • 3
  • 18
  • 26
6
votes
3 answers

htaccess vrs httpd.conf?

Is it still true that you shouldn't use htaccess files if you can use httpd.conf? The Apache site says "In general, you should never use .htaccess files unless you don't have access to the main server configuration file." But I don't know how old…
nedlud
  • 273
  • 2
  • 10
6
votes
2 answers

Finding Webserver Vulnerability

We operate a webserver farm hosting around 300 websites. Yesterday morning a script placed .htaccess files owned by www-data (the apache user) in every directory under the document_root of most (but not all) sites. The content of the .htaccess file…
Brent
  • 22,857
  • 19
  • 70
  • 102
6
votes
1 answer

URL rewrite with multiple parameters using .htaccess

I have four different types of rewrites I'm trying to do with multiple parameters in each. First, the URLs with no modification: http://www.example.com/index.php?p=/category/page-slug&pn=2/ http://www.example.com/index.php?p=/category/&f=feed/rss…
VirtuosiMedia
  • 183
  • 1
  • 1
  • 5
6
votes
5 answers

.htaccess being hacked repeatedly

About 4 or 5 days ago, a client came back to me saying that their site was being redirected to some other suspicious looking website from Google, Yahoo, etc., but it was working fine when the user enters the site URL in the browser address bar…
Aditya M P
  • 322
  • 2
  • 4
  • 14
6
votes
4 answers

How to create and edit .htaccess and .htpasswd locally on my computer and then upload to my site via ftp?

I'm making a website for a client, and I want to make a password protected directory. The problem is my account type only allows FTP, so is there any way to create the .htaccess and .htpasswd files locally on my computer so I can upload them via…
cstack
  • 163
  • 1
  • 2
  • 7
5
votes
2 answers

How to add/ignore a subfolder in htaccess file?

I have build an app at http://url/sdf19/ I have a .htaccess placed in /sdf19/ containing RewriteRule for clean urls. But I have built a PDF generating tool, which is in a subfolder /inc/tools. I need to link to it direct to run before headers.…
Brad Sullivan
  • 51
  • 1
  • 3
5
votes
2 answers

RewriteRule "P" flag results in server 500 error

I am using RewriteRule in my .htaccess file to modify an incoming URL. It works fine except I want the rule to act as a proxy, rather than a redirect. But if I append the [P] proxy flag to the rule then the rule triggers a 500 error. The Apache logs…
Bob Arlof
  • 171
  • 4