Questions tagged [htaccess]

Directory-level configuration file found mostly on Apache web servers

The .htaccess file is a configuration file for the Apache web server, allowing configuration settings to be made at a directory-specific level, overriding the server-wide or site-level settings in the main Apache config.

Most (though not all) 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 also has further information about mod_rewrite.

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

The htaccess file is used by the mod_rewrite module of the Apache webserver. It 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
  • Password protection of directories and files

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

1715 questions
24
votes
2 answers

htaccess execution order and priority

Can anyone explain to me in what order apache executes .htaccess files residing in different levels of the same path and how the rewrite rules therein are prioritized? For example, why doesn't the rewrite rule in the first .htaccess below work and…
ChrisR
  • 343
  • 1
  • 2
  • 6
20
votes
4 answers

How to enable use of .htaccess in Apache on Ubuntu?

I'm trying to enable use of htaccess file in Ubuntu 14.04 (Apache 2.4.7). I know that this question has many possible duplicates, but none of them helped me yet. .htaccess ErrorDocument 404 /404.html 000-default.conf
David Abgaryan
  • 345
  • 1
  • 3
  • 5
18
votes
2 answers

Font blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin'

we are experiencing this error in Google Chrome. We thought everything was set-up correct. But maybe not? Font from origin http://skin.cdn.com has been blocked from loading by Cross-Origin Resource Sharing policy: No …
snh_nl
  • 653
  • 2
  • 6
  • 17
18
votes
1 answer

How to pass GET parameters to rewritten URL?

I have an .htaccess rewrite rule like this: RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^search/(.*)$ search.php?q=$1 What this does is, if someone visits http://example.com/search/test the URI that is really…
Jake Wilson
  • 911
  • 2
  • 8
  • 19
18
votes
4 answers

How do I implement URL rewriting in my .htaccess file?

I'd like to do some URL rewriting (Why? See this question.) so that instead of users seeing addresses like labouseur.com/course-compilers.html they can instead see and use simply labouseur.com/course-compilers (Even better, maybe I should…
Alan
  • 763
  • 5
  • 10
16
votes
4 answers

Can the files robots.txt and sitemap.xml be dynamic through an .htaccess redirect?

I have a multilanguage and multidomain site. It runs through a unique CMS installation (Drupal), so I have a single root directory. So if I have a static robots.txt, there I only can show the files for a single domain, as far as I know. Could I put…
Cesar
  • 405
  • 5
  • 13
16
votes
2 answers

Can .htaccess slow down a site?

I'm working with a client on an e-commerce website. I implemented clean URLs using .htaccess. I also used .htaccess to solve canonical issues such as redirecting www to non-www and removing index.php from the URL. The website recently began to slow…
Cody Sharp
  • 453
  • 3
  • 9
16
votes
5 answers

How can I stop a bot attack on my site?

I have a site (built with wordpress) that is currently under a bot attack (as best I can tell). A file is being requested over and over, and the referrer is (almost every time) turkyoutube.org/player/player.swf. The file being requested is deep…
Travis Northcutt
  • 1,576
  • 2
  • 16
  • 27
15
votes
2 answers

Is it better to have an ErrorDocument 404 redirect back to the homepage or a standard 404 error page?

We run an ecommerce site that was setup by a third party ecommerce software provider, basic shop with product pages, basket and checkout. The third party vendor set up the htaccess file so that if a non-existent URL is enetered it redirects to the…
Craig Angus
  • 511
  • 3
  • 12
15
votes
4 answers

Removing non-www support

I'm not an advocate of the no-www movement. I like the www because it adds as a buffer to distinguish between our public and private/static sites. The problem is that with one of our sites, our traffic is split pretty much 50/50 between those that…
Mark Henderson
  • 4,994
  • 2
  • 29
  • 43
14
votes
6 answers

Forcing SSL and www in .htaccess

I'm looking for a way to force SSL and www. I've been able to force both separately but together I keep running into redirection issues. The following code works when handling a URL in this format: http://example.com and properly redirects to…
Stephen
  • 243
  • 2
  • 7
13
votes
4 answers

What are some resources for learning the ins and outs of .htaccess?

What are resources for learning the various things I can do with .htaccess?
delete
12
votes
1 answer

How are web applications like Tumblr, WordPress.com and Blogspot able to create subdomains for users so fast?

I am curious as to how web-applications are able to create sub-domains instantly for new users, for example, newuser.wordpress.com, or example.blogspot.com. If I need to create a new subdomain for a website it usually requires that I log onto the…
nicholaschris
  • 223
  • 1
  • 6
12
votes
1 answer

301 redirects for all except me

I want to have my site down for an hour and I was using order Deny,Allow Deny from all Allow from my.ip.add.ress but I don't like the default error page. Is there a 301 redirect where I can redirect everyone who is not on my IP address to a nice…
Chris Mccabe
  • 223
  • 1
  • 4
12
votes
11 answers

Need to Stop Bots from Killing my Webserver

I am having EXTREME bot problems on the some of my websites within my hosting account. The bots utilize over 98% of my CPU resources and 99% of my bandwidth for my entire hosting account. These bots are generating over 1 GB of traffic per hour for…
Sammy
  • 223
  • 1
  • 2
  • 5
1
2 3
99 100