Questions tagged [.htaccess]

Directory-level configuration file used by Apache web servers. Use this tag if and only if .htaccess content is directly involved in the topic. We know many people are using .htaccess, but kindly ask the members of the community to not use this tag, unless you know it is on-topic in your question. Also notice what the [tag:apache] tag has to say about questions about _configuring_ Apache httpd and their potential off-topicness on Stack Overflow

The .htaccess (hypertext access) file is a configuration file for the Apache web server, allowing configuration settings to be made at a directory-specific level. It overrides the server-wide or site-level settings in the main Apache server-level configuration but must be enabled in the server-level configuration to work.

Most (though not all) directory-specific Apache settings can be configured in .htaccess. One of the most common usages for it is URL redirection using mod_rewrite, which is used by many sites for SEO purposes and to provide easier-to-read URLs. The Apache documentation has further information about mod_rewrite as well as simpler solutions for many common use cases.

.htaccess files are also commonly used to define custom error pages (e.g. for 404 errors). They can also be used for specifying directory-specific security and user authentication, configuring the PHP installation, file handlers and MIME types, output compression, and more.

For more information on .htaccess files and how to use them, see the Apache documentation.

More information

Top Questions for reference

  1. Tips for debugging .htaccess rewrite rules
  2. Access-Control-Allow-Origin Multiple Origin Domains?
  3. How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess
  4. How does RewriteBase work in .htaccess
  5. htaccess redirect to https://www
  6. How to redirect all HTTP requests to HTTPS using .htaccess rules?
  7. Hidden features of mod_rewrite
  8. .htaccess redirect all pages to the homepage on a new domain
  9. Create subdomains on the fly with .htaccess (PHP)
  10. .htaccess mod_rewrite - how to exclude directory from rewrite rule
  11. Leverage browser caching for 3rd party JS

How to ask

  • Make sure you explain how .htaccess is involved in your question
  • Explain the expected behavior, the actual behavior and the difference between the two
  • Show the relevant part of the .htaccess
72915 questions
6
votes
1 answer

FallbackResource causes net::ERR_INCOMPLETE_CHUNKED_ENCODING

When I use a .htaccess that contains just this line: FallbackResource index.php I get this error on Chrome only: net::ERR_INCOMPLETE_CHUNKED_ENCODING The error appears only when access the root directory where the .htaccess is located. IE, if…
Juicy
  • 11,840
  • 35
  • 123
  • 212
6
votes
4 answers

.htaccess file not working on Ubuntu 14.04 with apache2

My .htaccess file doesn't work on my Ubuntu 14.04 with Apache 2. This is my file: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?pg=$1 How do i solve my problem?
user2297392
6
votes
1 answer

Using htaccess rewrite/redirect so single PHP file can display data according to GET/POST variables

Bear with me as I try to learn more about .htaccess redirect rules - I'm a UI guy by profession and I'm doing my best to enhance my coding skills languages other than HTML/CSS/PHP, etc So, what I have is an index.php file that contains a menu -…
revive
  • 831
  • 2
  • 15
  • 31
6
votes
2 answers

HTACCESS redirect using URL parameter ID number range

I'm hoping someone can help as this is proving difficult to figure out. I am trying to redirect via HTACCESS and mod_rewrite a number of pages that have a URL parameter ID value within a particular range (from 1 to 7603). Here is what I have so…
Daniel Lee
  • 367
  • 5
  • 20
6
votes
1 answer

How I can avoid requesting Basic Authentication when HTTP method is OPTIONS on Apache .htaccess?

I am using HTTP basic authentication (username & password) in a site including API endpoints hosted in Apache, I am doing something like this on .htaccess: AuthType Basic AuthName "Restricted Files" # (Following line optional) AuthBasicProvider…
dseminara
  • 11,665
  • 2
  • 20
  • 22
6
votes
3 answers

Security: Deny access to .hg/* via mod_rewrite

My website is a mercurial repository with multiple subrepositories. I need to make sure I'm denying access to all files in every .hg directory on the server. For example, I have http://example.com/.hg/ and http://example.com/subrepo1/.hg/ I've added…
tex
  • 2,756
  • 22
  • 31
6
votes
2 answers

Creating user friendly URLs with .htaccess file

I have two php files in the same directory posts.php and postdetails.php. The posts.php page lists all posts and postdetails.php displays the post when the postid is set like: postdetails.php?id=3 I want to make the posts and postdetails pages…
manlikeangus
  • 421
  • 9
  • 28
6
votes
3 answers

is if else conditions available on htaccess?

I have a .htaccess file in the folder "services" in my website and have to give two urls following content of htaccess #------------------------ RewriteEngine on RewriteRule ^(.*)$ index.php?n=$1 [L,QSA]…
Haris
  • 61
  • 1
  • 3
6
votes
1 answer

Openshift redirects wp-admin to https

In general option in wordpress, I have changed the wordpress directory to be on http://mywebsite.com but wordpress dashboard is still in htpps causing mixed content warning and images in dashboard are not displayed even after disabling mixed content…
Indra
  • 1,308
  • 3
  • 18
  • 24
6
votes
0 answers

Cache-Control Optimization in Meta and .htaccess

We want to learn and optimize caching for our website, and we have the following codes. In meta, we have: For pages 1-10, For pages 11-20,
1453939
  • 242
  • 5
  • 14
6
votes
1 answer

htaccess redirect url with parameters

I have hundreds of links like this: http://www.domain.com/index.php?tag=value I want to redirect all links to http://www.domain.com/value/ Example: Link1 http://www.domain.com/index.php?tag=LW1fdX49tR redirect to:…
user2151960
  • 185
  • 1
  • 1
  • 17
6
votes
7 answers

only default permalinks working wordpress others become 404 error

My problem is in my wordpress site only default permalinks is working.. When I change permalinks all pages become not found.. only home page is showing. When I change permalinks to postname .htaccess content change to # BEGIN WordPress
Girish Sasidharan
  • 582
  • 1
  • 5
  • 14
6
votes
1 answer

apache .htaccess to nginx rewrite rule

I need to change from apache to Nginx but the .htaccess doesn' work on the Nginx server. I got following in my Apache .htaccess: RewriteEngine On # always run through the indexfile RewriteRule .$ index.php # don't let people peek into directories…
Medda86
  • 1,582
  • 1
  • 12
  • 19
6
votes
2 answers

Wordpress redirect to subdirectory - wp-admin forwards to wrong login url

I moved a Wordpress site to a new server. The site is installed in a subdirectory and the .htaccess in the root forwards to it like so: RewriteEngine On RewriteCond $1 !(^wpfolder/) RewriteRule ^(.*)$ wpfolder/$1 [L] I've changed the site_url…
smrkem
  • 173
  • 3
  • 12
6
votes
4 answers

Magento - Using custom Environment Variables for sensitive database info

I know Magento stores the database connection details within the local.xml file, however our firm is trying to avoid passwords and other sensitive data being stored within our git repo's for security purposes. I know you can create Environment…
Zabs
  • 13,852
  • 45
  • 173
  • 297
1 2 3
99
100