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

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…
Artem Razin
  • 143
  • 5
4
votes
4 answers

Enable cross origin for subdomain

I have 2 subdomains, av.xyz.example and video.xyz.example. I want to enable CORS for video.xyz.example on av.xyz.example. I have added the following code snippet in the apache configuration file of av.xyz.com Header set Access-Control-Allow-Origin…
Rick Roy
  • 237
  • 1
  • 5
  • 15
4
votes
1 answer

Apache - Need to rewrite /contact/ to /contact.php

Using .htaccess from my previous question, I edited it to add a rewrite rule for rewriting /contact/ to /contact.php and /xyz/contact/ to /contact.php?lang=xyz. While the second one works, the first still looks for the actual directory which doesn't…
Polda18
  • 61
  • 1
  • 9
4
votes
1 answer

Nginx: config set up to make extensionless php pages work

I am trying to set up my first website with nginx and I cannot seem to make extensionless php pages to work. I would like my pages like /aboutme.php to appear as /aboutme or I would like to just change my URLs to /aboutme instead of /aboutme.php and…
Carol
  • 41
  • 1
  • 3
4
votes
0 answers

How to conditionally unset header in .htaccess file?

I'm trying to conditionally unset X-Frame-Options in an .htaccess file if the request URL begins with /store. This is the code I am working with in .htaccess: # Allow store iframe to be loaded from all locations SetEnvIf Request_URI "^/store"…
Chris
  • 273
  • 2
  • 5
  • 9
4
votes
1 answer

Configure the server & DNS like: Accept all domains that use our spesific nameservers

First, I will describe the problem: I have a domain portfolio website. Every domain have a forsale page like this: www.myportfoliosite.com/thedomainforsale.com I want to park my domains but I need only a simple redirection to our for sale page. I…
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
  • 3
  • 11
4
votes
1 answer

.htaccess: Allow all connections from local network, but require login for external

NB: This is not a duplicate, as the flagged post deals with older versions of apache. I've tried the solutions in that thread, also the one supposed to work on later versions, without success. There are several questions and answers that deals with…
knoten
  • 143
  • 1
  • 1
  • 6
4
votes
1 answer

Does Apache look at .htaccess files above a VirtualHost's DocumentRoot?

I am trying to setup a subdomain on a server of mine, where blog.domain.com serves the content from domain.com/blog/ Perhaps this is the wrong way of doing this entirely, but I have setup a blog.domain.com VirtualHost for this, whose DocumentRoot is…
obeattie
  • 304
  • 1
  • 6
  • 13
4
votes
1 answer

Apache: Disable *parsing* of htaccess in webdav

I have following directory layout: /var/www/ example.com/ logs/ html/ stuff/ Apache is configured to normally serve from /var/www/example.com/html I have configured webdav to work for the url…
Scheintod
  • 391
  • 1
  • 5
  • 17
4
votes
2 answers

How to change index page for one IP address?

I've installed another theme on my site and I need to improve it. How can I change the index file only for my IP address? My current htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com RewriteRule (.*)…
Rasvet
  • 53
  • 1
  • 5
4
votes
1 answer

Redirect automatically to subdirectory and also remove www

I want to do 2 things : redirect http://www.example.com (with www) to http://example.com/fr (without www, AND subdirectory) Of course, I also want http://example.com to redirect to http://example.com/fr. I saw this solution : RewriteCond…
4
votes
3 answers

How to block Baidu from indexing MP3 files?

Using Apache I want to prevent people from directly downloading music via url. I just want the flash player to play it. However Baidu MP3 found the files and is establishing direct downloads to my music. Is there a way I can prevent this with…
Moak
  • 734
  • 3
  • 10
  • 31
4
votes
5 answers

Testing htaccess for 500 server error without actual error

After reading some tutorials, I have created an error file, that should be displayed instead of 500 server error. I have added it to domain's root and added the following line to the bottom of .htaccess: ErrorDocument 500 /error.html Now the…
Domas
  • 161
  • 2
  • 5
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
  • 7