Questions tagged [.htaccess]

Directory-level configuration file found mostly on Apache web servers

Filter by
Sorted by
Tagged with
5 votes
2 answers
9k views

Redirecting from http to https in Apache

This is a canonical question about redirecting from http to https in Apache Related: Everything You Ever Wanted to Know About Mod_Rewrite Rules but Were Afraid to Ask I have an Appache web server ...
Augustin's user avatar
  • 117
14 votes
4 answers
4k views

Load time impact of htaccess

There are in general two possibilities of handling stuff on Apache: make configurations for folders one by one using htaccess file to fully resign htaccess and put all the rules into the httpd.conf ...
Evgeniy's user avatar
  • 255
3 votes
1 answer
5k views

Nginx rewite rules 403 error

I am having trouble with converting .htaccess files to nginx. I have 3 .htaccess files. The first .htaccess file is located in the document root and is as follows: Options +FollowSymLinks ...
Adrian's user avatar
  • 67
1 vote
1 answer
2k views

Relationship of ServerName, ServerAlias, host.file and how to define them in httpd-vhosts.conf

I wonder what is the relationship of ServerName & ServerAlias with host.file. As I know ServerName sets the hostname and port that the server uses to identify itself and ServerAlias is the ...
Petri's user avatar
  • 49
83 votes
4 answers
202k views

How to get Apache2 to redirect to a subdirectory

I am running apache2 on Debian etch, with multiple virtual hosts. I want to redirect so that http://git.example.com goes to http://git.example.com/git/ Should be really simple, but Google isn't ...
Hamish Downer's user avatar
61 votes
4 answers
131k views

How to redirect root and only root via htaccess?

I want to redirect only my root to another url, but maintain all the /sub/directories where they belong (and redirect) example: mysite.com/1 redirects to somewhere mysite.com/admin opens a page i ...
user avatar
9 votes
5 answers
5k views

How to prevent hot linking ("image theft" / "bandwidth theft") of ressources on my site?

I'm trying to write the "ultimate" anti hot linking .htaccess... You can find many examples/tutorials/generators on the net but many of them are wrong or incomplete (or even both). These are the ...
AlexV's user avatar
  • 179
12 votes
3 answers
51k views

Convert and redirect URL in uppercase to lowercase using .htaccess

I would like to redirect a URL with uppercase characters http://localhost/A/B to a lowercase version http://localhost/a/b using the .htaccess file. Using regex I can capture A and B but is it possible ...
tintin's user avatar
  • 445
4 votes
1 answer
14k views

Problems redirecting Error 400 Bad Request to custom page

I've edited my .htaccess file to the following : ErrorDocument 404 /index.php?page=page-not-found ErrorDocument 400 /index.php?page=bad-request Now the error 404 redirects correctly, yet if I enter ...
Paul's user avatar
  • 180
4 votes
2 answers
21k views

Denying access to all files except index.html apache

Could someone help me with apache .htaccess file to deny access to all files and sub directories except for index.html on the documentroot for an apache server? I tried: <Location /> Order ...
93196.93's user avatar
  • 291
2 votes
3 answers
9k views

Apache .htaccess trick to authenticate only once for all subdomains?

I'm using something like this in .htaccess file to restrict access to the website: AuthUserFile /some/directory/.passwd AuthGroupFile /dev/null AuthName EnterPassword AuthType Basic require valid-...
michuk's user avatar
  • 133
1 vote
0 answers
1k views

Apache .htaccess trick to authenticate only once for all subdomains? [duplicate]

Possible Duplicate: Apache .htaccess trick to authenticate only once for all subdomains? I'm using something like this in .htaccess file to restrict access to the website: AuthUserFile /some/...
michuk's user avatar
  • 133
15 votes
6 answers
2k views

to www or not to www [duplicate]

Possible Duplicate: What’s the point in having "www" in a URL? Should I use www in front of a URL or not? Some sites say we should and some say the opposite. Pros Cons If there is no www ...
user avatar
13 votes
1 answer
29k views

Either all Options must start with + or -, or no Option may [closed]

I have this line in a .htaccess file Options +SymLinksIfOwnerMatch ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch ExecCGI Includes ...
d0001's user avatar
  • 329
10 votes
3 answers
43k views

How to redirect from HTTPS to HTTP before server error?

I used to operate a website with an SSL certificate, but have stopped using the SSL certificate. The problem is that most of the external links to the website use the https:// prefix. I have tried ...
user981178's user avatar
10 votes
1 answer
8k views

Exclusion of a protected sub-url does not work on Apache 2.4?

I try to exclude a sub-url "/shop/api" from my protected website. It worked fine on different server on Apache/2.2.15 but now not with Apache/2.4.7? It always asks for the basic authentication. Any ...
megloff's user avatar
  • 413
8 votes
5 answers
11k views

How can I perform a syntax check on an .htaccess file in a shared hosting environment?

I have a build script (Perl) that modifies the .htaccess file when I deploy my applications. As a double-check, I'd like to be able to perform some sort of syntax checking on the created .htaccess ...
Danny's user avatar
  • 311
7 votes
4 answers
22k views

How to throw a 404 error from htaccess?

Everything I find seems to be about created a custom 404 page. That is not what I am trying to do. If I want to block access to a page I can do this in htaccess: RewriteRule pattern - [F] ...
JD Isaacks's user avatar
7 votes
5 answers
87k views

How do I use .htaccess to always redirect from HTTP to HTTPS? [duplicate]

There's a few similar questions which I tried to work out the answer from, but so far I have been unsuccessful. Please advise how I can always redirect http to https (and also remove www. from the ...
Nick Bolton's user avatar
  • 5,146
5 votes
4 answers
5k views

Returning 404 code for unauthorized attempts

I have an admin directory on my web server (http://test.com/admin) and I don't want unauthorized parties to access this /admin/ directory instead I want to return 404 error code for all unauthorized ...
5 votes
4 answers
20k views

How to redirect non-www to www without hardcoding using .htaccess?

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] ...causes a perfect, non-hardcoding 301 redirect from "www to non-www", ...
user avatar
4 votes
1 answer
4k views

force https with apache before .htpasswd

I have this in my .htaccess file RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://www.myweb.com/phpmyadmin$1 [R,L] AuthUserFile /var/www/myweb/.htpasswd AuthGroupFile /dev/null ...
learningtech's user avatar
  • 7,445
4 votes
1 answer
1k views

Can Apache .htaccess convert the percent-encoding in encoded URIs from Win-1252 to UTF-8?

I want to add a directive in my .htaccess, such that if the browser is pointed at a URI containing %E4 (ä) - or any other special character - the .htaccess automatically rewrites %E4 (ä) as %C3%A4 (ä)....
Rounin's user avatar
  • 143
3 votes
2 answers
309 views

Is there an Elegant solution to rewrite long image?query-urls into cachable_nice_urls, using only apache htaccess?

this is a pain in the ass-problem! Whicever genius solves this riddle will receive paypal donation to eat diner for two. Now lets get started. Given: most proxies, do not cache resources with a "?" in ...
Sam's user avatar
  • 423
3 votes
3 answers
8k views

Insecure Connection: issue on www redirect to non-www with https

I am not much familiar with server configurations, please help me on this issue: I have a Debian8 server and a SSL certificate, the SSL certificate only for My non-www domain so I would like to ...
Riyas Muhammed's user avatar
2 votes
2 answers
124 views

apache2 points non-www to root instead of website folder

I have few different vhost created and every one has its own folder in /var/www/ like this /var/www/example1/ /var/www/example2/ Now, when I type url with www www.example1.com it points to the /var/...
cikatomo's user avatar
  • 149
1 vote
1 answer
2k views

how to redirect www.example.com to example.com via htaccess while on zend framework

as you may know zend framework uses .htaccess for redirection purposes so when I tried to follow this advice: http://techpp.com/2010/06/28/how-to-redirect-www-urls-to-non-www-urls-and-non-www-to-www/ ...
kamikaze_pilot's user avatar
1 vote
2 answers
2k views

Mod ReWrite Catch-All Subdomain

Basically I want *.domain.com to pull up domain.com/*/ (not redirect). I went into the subdomains section of cPanel and set a wildcard for this domain. It appears to be resolving correctly, ie *....
zuk1's user avatar
  • 141
1 vote
2 answers
1k views

How to convert this very simple .htaccess to Nginx?

I'm using this .htaccess that pass everything after URL to $param, so example.com/news/id goes to PHP as $_GET['param']='news/id'. But Nginx is always throwing me to 404 page. My .htaccess: ...
Sandro Benevides's user avatar
1 vote
1 answer
246 views

Why servers error log states lots of file doesn't exist, but files are accessible and website works well

we migrated our website onto VPS server (CentOS 5.6 + Plesk 9.5), everything works nice, but one strange thing that i noticed in Plesk, is error_log file, most of the time it filled up with hundreds ...
Tim's user avatar
  • 11
1 vote
1 answer
4k views

How to allow to change php version via .htaccess in Apache?

I've a Centos 7 with Apache, I want to compile php 7.0 and 5.6 and configure that as PHP-FPM. How can I configure Apache to allow users to change php version using .htaccess? Example .htaccess entry: ...
Janek's user avatar
  • 15
0 votes
1 answer
5k views

.htaccess rules to stop DDoS POST flooding

We're under a distributed denial of service attack from traffic that looks like this: 49.146.161.175 - - [11/Jul/2014:00:43:42 -0400] "POST / HTTP/1.1" 500 557 "-" "Mozilla/4.0 (compatible; MSIE 6.0; ...
wired's user avatar
  • 1
0 votes
3 answers
1k views

apache rewrite to assign folders to domains

Please point me in the right direction. I am using .htaccess to set-up domains on my server. I need to domain.com to access files from /domain.com/* folder. If a file does not exist, load /domain....
Alex L's user avatar
  • 591
0 votes
0 answers
170 views

www+https redirection does not work even though redirection has been added in .htaccess file [duplicate]

I'm currently doing www+https redirection where I hope that my website able to redirect from http://example.com to https://www.example.com but it does not work even I have added redirection in ....
Petri's user avatar
  • 49
0 votes
0 answers
23 views

masking after redrection using .htaccess [duplicate]

I have read many examples that use the .htaccess file method to mask a url. None of them works for me. It might be something simple that I am missing. Please bare with me. Here is what i want to do: I ...
thermike's user avatar
0 votes
4 answers
1k views

403 Forbidden Access

Yesterday my supervisor mounted one of his directories onto my server. The problem is, I can't access them and I have no way of contacting him right now. When I type in the URL I get this error: ...
user avatar
0 votes
2 answers
2k views

My php homepage downloads index.php instead of being processed on Gandi.net

if I go to the homepage of my website http://www.website.com (on a brand new server) the index.php gets donwloaded instead than processed. I don't have the same problem on other folders. my .htaccess ...
alekone's user avatar
23 votes
2 answers
71k views

How should I use the <If> directive in .htaccess?

I'm trying to add a conditional statement using Apache's If directive in my .htaccess file. I have referenced this page http://httpd.apache.org/docs/trunk/mod/core.html#if but it doesn't elaborate ...
cwd's user avatar
  • 2,783
19 votes
2 answers
8k views

Break up a long line in a .htaccess file

I am setting a Content-Security-Policy header in my .htaccess file, and it has grown to be an extremely long single line, which is a bother to manage. Is there some way to break up this line into more ...
MaxPRafferty's user avatar
15 votes
4 answers
59k views

IIS7: How to block access with a web.config file?

I know that IIS7 allows me to have a per directory configuration with the web.config xml file. I have a directory with some configuration files that don't want to be web accessible. A local web.config ...
neves's user avatar
  • 1,250
13 votes
5 answers
25k views

Does it matter in which order rules are placed in htaccess?

I hope this is a simple YES or NO answer (please specify why) Q1: Does it matter in which order rules are placed in htaccess? Especially when they are completely separated items. Q2: If yes, am I ...
Sam's user avatar
  • 423
12 votes
1 answer
16k views

max length of url 257 characters for mod_rewrite?

My url scheme is /foo/var1-var2-var3.../bar I am using these mod_rewrite rules: RewriteBase /foo/ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ...
Daniel's user avatar
  • 125
11 votes
1 answer
74k views

Increase the value of LimitRequestFieldSize in Apache

I have developed an application which uses a jQuery plugin, which in turn uses excessive cookie data. The problem is, after every 15-20 request I am shown this error message by the browser: Your ...
Ibrahim Azhar Armar's user avatar
10 votes
4 answers
21k views

Why do .htaccess redirects work in http but not with https?

I have a simple .htaccess file that works great on the http version of the site but not when I go to https. Why? RewriteEngine on #This is so if the file exists then use the file RewriteCond %{...
Sheldon McGee's user avatar
8 votes
1 answer
9k views

.htaccess Redirect 301 with trailing slash adds trailing slash to destination

Just had my website re-done and am trying to set up redirects in the .htaccess file for links that have changed This works fine, except it doesn't work for /example/ (with trailing slash on source ...
Chris Dutrow's user avatar
7 votes
2 answers
16k views

IIS Basic Authorization ala .htaccess/.htpasswd in apache

How do I implement the protection of the pages (asp.net mvc app), so when I hit the home page or any other pages within the application I get a login dialog popup in the browser I'm looking for ...
Dmitry's user avatar
  • 201
6 votes
3 answers
16k views

Creating a cookie-free domain to serve static content

I am trying to create a "example.com" domain to serve static content to my original domain. How would I make the "example.com" domain to so its cookie-free when loading content? I am thinking that ...
pawelglow's user avatar
  • 163
6 votes
3 answers
10k views

How can I password prompt certain IPs and allow all others free access using Apache?

SOLVED: The idea is that if the visitor comes from China they have to pass a basic authentication. If you have any other IP address you can visit the site without being hassled (including proxies) //...
Moak's user avatar
  • 784
6 votes
5 answers
9k views

.htaccess being hacked repeatedly [duplicate]

About 4 or 5 days ago, a client came back to me saying that their site was being redirected to some other suspicious looking website from Google, Yahoo, etc., but it was working fine when the user ...
Aditya M P's user avatar
6 votes
1 answer
9k views

Whitelist an Individual's IPv6 Range via .htaccess

I have a section on a website that blocks access to all IPs, except for those that are whitelisted. For IPv4, this is very simple, because even with dynamic IPs, they generally won't changed for ...
IPv6Quest's user avatar