Arquivo da tag: htaccess generator

Redirect WordPress RSS to Feedburner

Redirect WordPress RSS to Feedburner

Feedburner is loved my many. But by default WordPress have its own RSS which doesn’t need any extra configuration. In order to redirect the default WordPress RSS to Feedburner, here is the hack.

# temp redirect wordpress content feeds to feedburner

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/YOURFEEDNAME [R=302,NC,L]

Redirect www to non www or vice versa

Redirect www to non www or vice versa

Normally we like to keep our URL short. This has also become a trend to keep your site name shorter as much as possible. So removing the www can considerably makes a positive effect for blogs with longer domain name.

Redirect www to non www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourblogname.com [NC]
RewriteRule ^(.*)$ http://yourblogname.com/$1 [L,R=301]

Redirect non www to www

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourblogname.com [NC]
RewriteRule ^(.*)$ http://www.yourblogname.com/$1 [L,R=301]

Redirect visitors to maintenance page

Redirect visitors to maintenance page

We often change our WordPress theme. When changing the themes, normally the visitors encounter with strange errors. At this situation, we have to redirect the visitors to a maintenance web page except for the admin.

In the snippet below, change your maintenance page name and on REMOTE_ADDR type in your IP. Make sure that you have a static IP before trying this hack.

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^123.123.123.123
RewriteRule $ /maintenance.html [R=302,L]

Restricting IP’s of comment spammers

Restricting IP’s of comment spammers

Askimet is a beautiful tool to keep us free from spam comments. If you are not using Askimet, but want to just block certain IP’s of spammers, here is the tip

order deny,allow
deny from 12.23.34.56
deny from 45.67.78.90
allow from all

Stop images used in post from hotlinking

Stop images used in post from hotlinking

This happens to most of the blogs, who write tutorials where the other blogger shares your post on his blog by hotlinking your images. Going through this way, all the image shared in his blogs, takes your server bandwidth to load those images. The .htaccess hack used here will stop hotlinking of images and display a default image for hotlinked images. So create a new image with the name of stophotlink.jpg and upload it to your image folder.

RewriteEngine On
#Replace ?mysite.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+.)?yourblog.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your “don’t hotlink” image url
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/stophotlink.jpg [L]

Redirect post with date and name to post with postname

Redirect post with date and name to post with postname

Some of like to display post with date, month, year and postname. For those who wish to redirect all the post under this permalink to /%postname%/ this; here is the hack.

RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.yourblogdomain.com/$4

Remove the /category/ from WordPress category permalink

Remove the /category/ from WordPress category permalink

Personally I am not a big fan of /category/. If you look at some popular blogs, you can see them having categories http://yourdomain.com/wordpress instead of http://yourdomain.com/category/wordpress

RewriteRule ^category/(.+)$ http://www.yourblogname.com/$1 [R=301,L]