Category Archives: Htaccess

Htaccess redirect from www domain to non-www domain

Permamently redirect all users that visit the www domain to the non-www domain. In short, remove the “www” from the domain using mod_rewrite and .htaccess file. Write this text in your .htaccess file: RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC] RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC] RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]

Htaccess Prevent Hotlinking Images

Write this text in your .htaccess file: RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?YourDomain [NC] RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?YourDomain [NC] RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L] Change YourDomain with the name of your domain.

Redirect WordPress Feed to FeedBurner

Edit the .htaccess file and add this text: RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/your_feed_name [R=302,NC,L]RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/your_feed_name [R=302,NC,L]

Block Bad Bots with Htaccess

Bots are automated scripts that are used to crawl your website. Legit bots are, for example, Google Bot or Bing Bot used to index the pages on your website. Bad bots are scripts used to find vulnerabilities on your website by crawling web pages to search for vulnerable scripts, or spam bots that steal email […]

Disable TRACE or TRACK method in Apache

TRACE and TRACK are HTTP request methods used for debugging purposes. Having these request methods enabled in your web server may lead to security risk that may compromise the security of your website and an attacker may manipulate these HTTP request methods to steal sensitive data of users. Disable Trace and Track with mod_rewrite Add […]