how to write htaccess rules?

February 25, 2015 at 13:08:44
Specs: Windows 7
Hi!,
I have 2 rules declarations in htaccess

1) To prevent HOT LINKING

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]

RewriteCond %{HTTP_REFERER} !^http://example.com$ [NC]

RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC]

RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC]

RewriteRule .*\.(.*)$ http://www.example.com [R,NC]

2) To redirect "example.com" to "www.example.com"


RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]

RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

How can i declare both in combined and efficient form (so that both works) in my htaccess file???


See More: how to write htaccess rules?

Report •

#1
February 26, 2015 at 11:59:34
try to use this
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]

replace domain.com with your domain


Report •

#2
February 26, 2015 at 12:43:04
Hi there,


RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC]

should be

RewriteRule %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC]

AND there should be L (last rule somewhere, like

RewriteRule \.(gif|jpg|js|css)$ - [F,L]

Am I correct??


Report •
Related Solutions


Ask Question