Smartlab Software logo

htaccess Tips

Helpful htaccess tips for an Apache server.

301 Redirect

In order not to lose valuable rankings with a web page that has been indexed it needs to be redirected if it is ever deleted or the filename is changed.

redirect 301 /old-web-page.htm

If your web path has spaces in it, use double quotes:

redirect 301 "/abc/web page.html"

To test out the redirect enter in the old web page URL in your browser. It should redirect to the new web page.

Referrer Spam

Redirects referrer spam to a forbidden page or a website of your choice..

# Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?*$ [OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?*$ [NC]
RewriteRule .* - [F,L]
The last line can be replaced by:
RewriteRule \.*$ [R,L]
which will redirect a referrer spammer to another website.
If you wish to block access based on an IP address use this:
# Deny access based on the IP address or host name of the offending site
 <Directory /usr/local/etc/httpd/htdocs>
   Deny from
   Deny from

Related resources