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

Precedence of .htaccess for cache control

I have a .htaccess in my document root, with the following: ExpiresActive On ExpiresDefault A0 ExpiresDefault A86400 However, for a particular sub directory,…
Ying Fan
1
vote
2 answers

How Do I Cache Just the Homepage with Apache .htaccess?

This config is close... Header set Cache-Control "max-age=7200, must-revalidate" ...but it does all php pages, not just the home page like I want. Basically the developer said he wants example.com to be cached,…
ServerChecker
  • 1,518
  • 2
  • 14
  • 35
1
vote
1 answer

.htaccess password not working for all files

My .htaccess on Rackspace looks like this: AuthType Basic AuthName "Restricted Area" AuthUserFile /path-to-htdocs/.htpasswd Require valid-user Now I would expect this to password protect the whole directory, however, it only protects files with…
hplbsh
  • 131
  • 6
1
vote
1 answer

How to limit web access by password and IP address using .htaccess?

We're trying to lock down our administrative site by requiring a password AND requiring that the request is coming from an authorized IP address. We've figured out how to do both separately, but can't figure out how to combine the two. AuthName …
kenja
  • 115
  • 2
  • 5
1
vote
1 answer

passing URL vars to a wordpress page and pretty-fying it with .htaccess

I have wordpress installed in a directory called welcome, and /welcome/samples is a "page" (created via Wordpress). It's has a php template waiting for a $_REQUEST['category'] When a user goes to /welcome/samples/fun, I want to have "fun" passed to…
Jonah
  • 123
  • 1
  • 3
1
vote
2 answers

.htaccess to redirect any URL from a domain to a fixed URL on another domain

Anyone can help me out with an .htaccess I'm trying to create? I want to redirect foo.com to foo.ca. Any URL from foo.com (with or without www and under http or https) will all be redirected to www.foo.ca. Some examples: http://www.foo.com/ -->…
AlexV
  • 179
  • 1
  • 2
  • 16
1
vote
1 answer

Rewrite /url/path/index.php to /url/path

I can't quite figure out how to use a regex in my .htaccess file to remove index.php from the end of a URL if and only if it is the last thing in the string. If the url is example.com/path/index.php, it should turn into: example.com/path/ But if the…
geerlingguy
  • 1,357
  • 2
  • 17
  • 29
1
vote
1 answer

Redirecting to a diferent exe for download based on user agent

I own a Linux-Apache site where I host exe files for download. Now, when a user clicks this link to my site (published on another site): http://mysite.com/downloads/file.exe I need to dynamically check their user agent and redirect them to…
Ra.
  • 217
  • 5
  • 11
1
vote
1 answer

htaccess redirects with special characters on an specific url not working

I need some help creating a redirect, I'm trying to replace all - to +, but both are special characters and also want to do it only when the URL contains ?s=. This is an…
1
vote
1 answer

Edit .htaccess file to make file accessible

I was trying to make a WordPress plugin work, when I found, after hours of debugging, trial, errors and praying ancient Greek gods, that the plugin did not work because it was impossible for the server to reach a particular file. The website is…
1
vote
0 answers

htaccess: I can't redirect to nested subfolders correctly on the WordPress app

I have a multilingual WordPress site that has two languages: en and tr, It's site A. I wanna put my other WordPress site inside /tr/shop/ folder, It's site B. Just need only these rules: /en/anything/ goes to site A (also /en/) /tr/anything/ goes…
user1034636
1
vote
1 answer

how to write 301 redirect by checking an special character from the url using htaccess?

I have few urls contain some special characters like below www.abc.com/archive/category/コレクション-帯-袋帯 www.abc.com/archive/category/お役立ち情報 I want to write .htaccess to handle this redirection. I tried this way but its not working RewriteCond…
Khan Emir
  • 11
  • 1
1
vote
1 answer

Apache RedirectMatch not matching double slash

I want to redirect URLs with multiple consecutive slashes (e.g. //) in the path to have only one consecutive slash, e.g. https://example.com/a//b/c/ → https://example.com/a/b/c/. My .htaccess file contains the following statement. RedirectMatch 301…
fionn
  • 13
  • 5
1
vote
3 answers

htaccess SSL redirect

Currently the coder has the following line in the .htaccess file: RewriteRule ^registration$ registration.php I understand what this means. However I also want to redirect domain.com/registration to https://domain.com/registration Anybody know how…
Fiona
  • 237
  • 1
  • 2
  • 6
1
vote
1 answer

htaccess - Generate ALLOW rule dynamically from external file

Can Htaccess set variables by external files as values? I would like to ALLOW all IPs that are listed in a txt file located on the server. This txt file is auto generated via script by our systems that resolve DYNDNS adresses to IPs. I can format…
MastaP
  • 111
  • 3