Posts Tagged ‘htaccess’

How to Block a Countries IP’s, block of IP’s

August 5th, 2011

Once in a while you want to block all traffic from a country or countries. I use to think it was not possible till i was pointed to the following website:

http://www.countryipblocks.net/

It will create a variety of block lists (including .htaccess) based on what country you want to block from your webpage. This is great for security or just limiting your customer base.

if you found this helpful feel free to donate to:
ZEC: t1NQp1UuqQbmnXzazbLTSreS2AbaZpRBuTM
LTC: LZyNF1qkBUA7XFz83m5xwzGgmmj1owQn9d
BTC: 1PY95KFPTEJTR7f2NnSgaB6xB9pwDJkcJz

.htaccess – redirect from http to https, port 80 to port 443

August 11th, 2010

The following .htaccess rules will autoforward an individual from a port 80 (also the regular http) to 443 (also known as https://)

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Please, note that the .htaccess should be located in the web site main folder.

In case you wish to force HTTPS for a particular folder you can use:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]

The .htaccess file should be placed in the folder where you need to force HTTPS.

if you found this helpful feel free to donate to:
ZEC: t1NQp1UuqQbmnXzazbLTSreS2AbaZpRBuTM
LTC: LZyNF1qkBUA7XFz83m5xwzGgmmj1owQn9d
BTC: 1PY95KFPTEJTR7f2NnSgaB6xB9pwDJkcJz

.htaccess – redirect from http to https

February 23rd, 2010

The simplest code i have found so far to redirect from http to https is:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Just place this in your .htaccess file and it should work.  The same principal can be used to redirect users from https to http with

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Finally to redirect a user from 1 port (any port) to another you could use:

RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule (.*) http://www.example.com:newport/ [R]

This will redirect from 443 to “newport”.

if you found this helpful feel free to donate to:
ZEC: t1NQp1UuqQbmnXzazbLTSreS2AbaZpRBuTM
LTC: LZyNF1qkBUA7XFz83m5xwzGgmmj1owQn9d
BTC: 1PY95KFPTEJTR7f2NnSgaB6xB9pwDJkcJz

.Htaccess – Password Protect a Directory

February 4th, 2010

To password protect a directory do the following.

First log into the hosting space using the command line. Once logged in run the following and record the required information.

pwd <– get the full path of the current directory, this is the [PATH]

Example output would be : /var/www/www.sogoth.com/web

Now run the following command:

htpasswd -c .htpasswd [username]

[username] is just a login name for 1 of the accounts you wish to access the password protected folder. You can have multiple users, but must run the command once for each user.

Example :
htpasswd -c .htpasswd exampleuser
New password:
Re-type new password:

Once complete go to the folder you wish to protect and create a new file .htaccess.

In this file add the following:

AuthUserFile [PATH].htpasswd
AuthGroupFile /dev/null
AuthName ByPassword
AuthType Basic
<Limit GET POST>
require user [username]
</Limit>

For my example it would be:
AuthUserFile /var/www/www.sogoth.com/web/.htpasswd
AuthGroupFile /dev/null
AuthName ByPassword
AuthType Basic
<Limit GET POST>
require user exampleuser
</Limit>


Now visit the website location and you should have a login screen. Type in the username and password and you should have access.

if you found this helpful feel free to donate to:
ZEC: t1NQp1UuqQbmnXzazbLTSreS2AbaZpRBuTM
LTC: LZyNF1qkBUA7XFz83m5xwzGgmmj1owQn9d
BTC: 1PY95KFPTEJTR7f2NnSgaB6xB9pwDJkcJz