To configure URL forwarding using mod_rewrite:
I. ENABLE .HTACCESS
- Login to the Netfirms Control Panel at https://controlpanel.netfirms.com
- Click Site Tools
- Click .htaccess
- Enable .htaccess
II. CONFIGURE YOUR .HTACCESS FILE USING REWRITE ENGINE (mod_rewrite)
Example #1:
NOTE: The RewriteBase cannot be empty. It must indidcate the base directory or a referring directory.
Example #2:
Example #3:
RewriteEngine On
RewriteRule ^tutorials/(.*)/(.*).php /tutorials.php?req=tutorial&tut_id=$1&page=$2
Example #4:
The following will display contents in newpage.html when visitor browses to oldpage.html:
RewriteEngine on
RewriteRule ^oldpage.html$ /newpage.html
Example #5:
The following will rewrite the URL to http://yourdomain.com/directory/newpage.html when visitors browse to http://yourdomain.com/anypage.html
RewriteEngine on
RewriteRule ^([a-z]+).html$ /directory/newpage.html [R,NC,L] The following will display contents of http://yourdomain.com/folder1/folder2/folder3/index.php when visitors browse to http://yourdomain.com/folder1/index.php (while maintaining http://yourdomain.com/folder1/index.php in the address bar of the browser)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder2/folder3/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.php
RewriteRule (.*) /index.php/$1 [L]
RewriteRule ^$ /$1 [L]
</IfModule> Example #6:
The following example will forward a visitor coming from a specified IP address (eg. 123.45.67.8) to another location (eg. /):
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^123.45.67.8$
RewriteRule ^.*$ - [F]
The
following example will forward a visitor coming from a specified IP
address (eg. 123.45.67.8) to another location (eg. /) if they try to
access any .php files:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^123.45.67.8$
RewriteRule .php$ - [F]
Another example of a similar .htaccess file using ip blocking in RewriteCond directive will forward user to http://www.yahoo.com URL if they come from a specified IP address (eg. 123.45.67.8): RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^123.45.67.8$
RewriteRule ^(.*)$ http://www.yahoo.com [L]
Example #7:
Hot
linking (ie. bandwidth stealing) happens when people link to files and
images on a different server, display them on their website and the
bandwidth is at the other website owner's expense. The following
example can prevent hot linking to your website:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?yourdomain/.*$ [NC]
RewriteRule .(gif|jpg)$ http://yourdomain.com/image.gif [R,L]
Other Examples of .htaccess configurations:
Example #8:
If
you have problems with certain visitors to your website, you can ban
them. There are two different ways to ban visitors: (1) using their IP
address they came from or (2) using the domain name which they came
from.
The following example denies a visitor coming from IP address 123.45.67.8:
order allow,deny
deny from 123.45.67.8
allow from all
The following example denies visitors coming from a block of IP addresses coming from 123.45.67.0 to 123.45.67.255
order allow,deny
deny from 123.45.67.
allow from all
The following example denies a user by the domain name from which they came from:
order allow,deny
deny from www.theirdomain.com
allow from all
The following example denies a visitor from a domain name and all subdomains within the domain name:
order allow,deny
deny from .theirdomain.com
allow from all
The following example denies all visitors except your own IP address assigned to you by your ISP (Internet Service Provider):
Order deny,allow
Deny from all
Allow from youripaddress
Example #9:
The following example denies access to all files if the visitor is browsing from IP address 123.45.67.8:<Files *>
Order allow,deny
Deny from 123.45.67.8
Satisfy All
</Files>