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

Apache htaccess -> Nginx rewrites

Help me please to write nginx rewrites instead of that Apache htaccess: Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-d …
tst
1
vote
1 answer

How to chain rewrites in Nginx?

I'm new to nginx's rewrite engine. I'm trying to convert my old htaccess file over to nginx's format but I'm running into some trouble. # ------------------------------------------------------ # # This redirects index.php to / …
Chris
  • 31
  • 1
  • 5
1
vote
3 answers

how can vbulletin and apache share passwords

We currently have a website that uses .htaccess to control access to some pages. We also have vBulletin running which uses a different set of credentials. What is the best way to tie these two together so they can use the same user name and…
JonDrnek
  • 247
  • 1
  • 3
  • 7
1
vote
2 answers

Using htaccess to serve file from a remote server

Is it possible to do this using htaccess? User access -> http:// mydomaina.com/dir/filename and it will display the content from -> http:// mymainsite.com/anydir/mydomaina-filename i did have a htaccess code but its not working maybe theres…
Jrubins
  • 13
  • 2
1
vote
2 answers

.htaccess 301 redirect with regex

I am trying to fix a lot of errors in our old website regarding a thing with product pages having multiple URLs associated with a single product. I am hoping that I can use regular expressions in with a regular redirect 301 line but so far I cannot…
Josh Pennington
  • 288
  • 1
  • 6
  • 21
1
vote
2 answers

htaccess .html rewrite exception

Ok guys I need to add an exception! How can I do this? I currently use RewriteRule ([^.]+).html $1 [R=301,L] to rewrite all .html urls I do need the exception for the google.html verification file. How can I set this exception? I tried this but it…
Jason
1
vote
3 answers

Can't seem to get mod_rewrite to set an environment variable

This is just plain weird. I have put the following in an .htaccess file: RewriteRule ^a-file-on-the-server$ index.php [E=let_me_in:test] And in my PHP script, I have the following: print_r($_ENV); ...which prints out all the environment…
Nathan Osman
  • 2,725
  • 7
  • 32
  • 46
1
vote
1 answer

Stop WordPress from hi-jacking CodeIgniter URLs using .htaccess

WordPress is installed in the root web directory: /var/www/html/ CodeIgniter is installed in a sub-directory: /var/www/html/ciapp/ When I access http://www.example.com/ciapp/ the main CI controller is accessed and executed correctly. However, if I…
Jake Wilson
  • 8,814
  • 29
  • 97
  • 125
1
vote
2 answers

Why does php not run from aliased directory?

I am trying to use nclud's windex to stylise my apache directory listings for an internal project (security isn't too much of a concern) Windex uses a HeaderName and ReadmeName directive pointing to php files, and it all works so long as the windex…
James Booker
  • 33
  • 1
  • 5
1
vote
1 answer

How do I ignore a part of the URL?

My current rewrite rules looks like: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond ${REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_URI} ^/video/(.*)$ RewriteRule ^(.*)$ /video/index.php [L] URL's like…
lurtz
1
vote
2 answers

Deny access to the site, based on QUERY_STRING

My site is "under attack" : bots from many different IPs are filling a form with spammy content. IP addresses can't be filtered, they are always different, so I was thinking to filter by QUERY_STRING, to match an URI like…
Omiod
  • 137
  • 2
  • 6
1
vote
1 answer

How to password protect Apache's auto-generated directory index/listings?

I like the built in indexing that apache can do, I use it a lot to navigate certain files of mine. The problem I run into is that I normally leave a directory with no index.html so that I can view the index this way, but it allows the public to also…
Brian
1
vote
1 answer

mod_rewrite rule for images with query string

I'm a mod_rewrite novice and a regex noob, but here's what I want to do: I've got a script that will re-size images on the fly. I'd like to be able to take any image file path, add a query string to it, and have it automatically sent to the script…
Bryan M.
  • 161
  • 8
1
vote
1 answer

.htaccess 400 bad request

htaccess: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php RewriteRule ^site-css/([0-9]+)/(.*)$ ../application/site/$1/design/css/$2…
azz0r
  • 149
  • 3
  • 12
1
vote
8 answers

htaccess location

I need to edit the htaccess file on my server. Problem is, I can't find it. Any idea where it would be?
codedude
  • 117
  • 1
  • 1
  • 6