htaccess block access by referer
Posted by Wil in htaccess tutorials on June 27th, 2009
If your server is over – spammed, this .htaccess configurationwill help you. By blocking website access by referrer you are disabling any impressions that come from “wrong” referrer. It could be “bad” bot that uses your website resources in it’s needs. You can block “bad” bots or urls from visiting your website by editing .htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} botsite\.com [NC,OR]
RewriteCond %{HTTP_REFERER} othersite\.com [NC,OR]
RewriteRule .* – [F]
</ifModule>
Domains marked in bold are wrong referrer domains, and we don’t want any traffic from.
Modify your .htaccess file and add “wrong” bots or referrers to disable resources stealing.
htaccess rewrite rule
Posted by Wil in htaccess tutorials on June 27th, 2009
To enable rewrite rule and rewrite commands you will need to enable apache rewrite engine.
Add this code to your .htaccess to enable rewrite commands of your server :
RewriteEngine on
htaccess Redirect File Or Directory
Posted by Wil in htaccess tutorials on June 27th, 2009
If you moved files from one directory or changed directory location, you will find it useful to redirect all your visitors to the true directory that contains all the files in it . Apache server was designed to allow manually redirection of all your traffic from “wrong” directory to the true directory, this method is also excellent for SEO practice, wrong pages will not been cached by search engines.
Here is .htaccess code for this task :
redirect 301 /oldfiles/mypage.html http://www.example.com/newfiles/mypage.html
We used 301 redirect command to redirect one file from one directory to another , and you should specify your “wrong” path (/oldfiles/mypage.html) and “true” path (http://www.example.com/newfiles/mypage.html)
Sometimes we will throw our traffic to the new directory permanently , and here is .htaccess code
Redirect permanent /oldfiles/ http://www.example.com/newfiles/
You can modify your .htaccess file in your free time.
Good luck.
htaccess redirect site
Posted by Wil in htaccess tutorials on June 27th, 2009
There are a lot of reasons to redirect website from one to another, for example when you changed your main domain name and want all traffic to be redirected to your new website domain name.
Instead of using slow html meta redirect function, it is a good idea to send command to your server directly.
Here is the code for .htaccess file to send your visitors to another domain name:
RewriteEngine On
RewriteRule ^(.*)$ http://www.htaccessfile.com/$1 [R=301,L]
Where http://www.htaccessfile.com is desired url you want to send traffic to.
If you want redirect to be permanent, you can use this command :
Redirect permanent / http://www.domain.com/
htaccess Allow Override
Posted by Wil in htaccess tutorials on June 27th, 2009
Htaccess allow override is a perfect solution to increase your website performance. Allow Override enables searching of .htaccess file in all website directories, to specify which directory contains allow override and which directory doesn’t we will use allow override command.
We will disable allow override in our root folder and enable allow override in other website directories.
AllowOverride None
Our each directory will contain allow override enabled
<Directory /public_html/foldername>
AllowOverride Options
</Directory>
/public_html/foldername is a directory contains .htaccess file.
Well, this method increases your website load times and improves your website webs appearance in search engines.
htaccess protect website from content ripping
Posted by Wil in htaccess tutorials on June 27th, 2009
It’s really sad to realize that your website is not unique anymore, someone ripped all the content, mysql database and even your name mentioned in it and built his scam website with your content.
It is a good idea to protect your blog or website from ripping software, here is the sollution, you can tell your apache server via .htaccess to block unwanted bots. You can add additional bots in this list.
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]
RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
If you know additional ripping software, please leave comments.
htaccess allow IP addresses
Posted by Wil in htaccess tutorials on June 27th, 2009
There are lot’s of programs that allow ripping website content and mysql databases. All the ripped content transferred to another websites, thanks god we have google that figures out plagiarism by caching dates. Anyway sometimes there are many unnecessary bots of authomatic websites that steal our traffic. Sometimes there is any unwanted spammer or proxy website user that visits our website frequently. htaccess file allows to block unwanted visits by IP.
If your website under construction, you can simply edit .htaccess file to disallow visits to your website.
Here is the code :
<Limit GET POST PUT>
order deny,allow
deny from all
allow from 12.345.67.890
</Limit>
allow from 12.345.67.890 command allows access to your server only from 12.345.67.890 IP address.
You can allow more IP’s to access your website :
<Limit GET POST PUT>
order deny,allow
deny from all
allow from 12.345.67.890
allow from 890.67.345.12
</Limit>
This practice is good in case you are modifying your website and don’t want others to see the process, other reason to use it when you have some webpage visible only to allowed IP’s – your customers.
htaccess admin email address
Posted by Wil in htaccess tutorials on June 27th, 2009
Sometimes it is necessarry to define admin email address for the server, if our website hosted somewhere and we are not able to configure Apache configuration files, we will use .htaccess file to configure default admin email address of our website. The code is shown below, you can test this code with your .htaccess file.
SetEnv SERVER_ADMIN yourname@example.com
( yourname@example.com is your email address. )
zend framework htaccess rewrite rule
Posted by Wil in zend framework htaccess on June 27th, 2009
This tutorial is about how to create rewrite rule for zend framework installed on Apache server Ubuntu linux operating system.
Once you finished your apache/php/ mysql installation , you will need to configure apache virtual host for your new project.
open etc/apache2/sites-enabled directory, you will see file called 000-default, this is default apache configuration file you will need to create new file called just like your project directory. For example, in your var/www/ directory you have a folder named /zendtest , created file should be called zendtest, file should be without any extension.
Edit created file and insert these lines :
Our directory structure is just like mentioned on Zend Framework Quick start, please visit Zend Framework website for more information.
ServerAdmin webmaster@localhost
ServerName zendtest
DocumentRoot /var/www/zendtest/public
ErrorLog /var/log/apache2/mysite_error.log
CustomLog /var/log/apache2/mysite_access.log combined
# this entry is necessary to allow the virtual host to enable mod rewrite using htaccess
Options Indexes FollowSymLinks
AllowOverride All
allow from all
Our project located in the public directory, there is the place for our .htaccess file.
Go to your web root directory, in our case is /var/www/zendtest/public (we redirected virtual host to this directory, check out apache code below) Create file called .htaccess and put these lines inside :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Now let’s restart apache, the command to restart apache is sudo etc/init.d/apache2 restart (if you are not sure what is your apache version, open /etc directory and find apache directory, it may be 2 or 2_2)