Mostly about my amusement

Tag: RewriteRule (page 1 of 1)

.htaccess fix for machine translation

The current version of ATPP is 5.1 and it works really well. But occasionally I get speed bumps from Babelfish and Google translation engines so I end up turning it off for a while.

Without the plugin, when someone goes to the translated version of a posting, they get redirected to the home page.

For example the German pages for Andre’s trip to Disneyland is

http://blog.dembowski.net/2008/01/30/andres-trip-to-disneyland/de/

When I turn off the plugin users get sent to

http://blog.dembowski.net/

Here is where .htaccess comes to the rescue. By adding lines at the top of my .htaccess file I can send the request for a translated post to the English version:

RewriteRule ^de/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^zh/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^ko/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^ja/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^pt/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^it/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^es/ http://blog.dembowski.net/ [R=302,L]
RewriteRule ^(.*)/de/ http://blog.dembowski.net/$1/ [R=302,L]
RewriteRule ^(.*)/zh/ http://blog.dembowski.net/$1/ [R=302,L]
RewriteRule ^(.*)/ko/ http://blog.dembowski.net/$1/ [R=302,L]
RewriteRule ^(.*)/ja/ http://blog.dembowski.net/$1/ [R=302,L]
RewriteRule ^(.*)/pt/ http://blog.dembowski.net/$1/ [R=302,L]
RewriteRule ^(.*)/it/ http://blog.dembowski.net/$1/ [R=302,L]
RewriteRule ^(.*)/es/ http://blog.dembowski.net/$1/ [R=302,L]

The request from /some/url/here/de/ results in the Apache server sending back a 302 temporarily moved to the same URL minus the two letter language code.

If I have to turn off the ATPP plugin for an extended time, I can do so knowing that search engine visitors will still find the original post.

Update: added portion for languages off of the root i.e. http://blog.dembowski.net/es/ becomes http://blog.dembowski.net/

Internet! You kids get off the lawn!

I have a few blog entries about Gundam episodes and Gunpla and I often put up graphics either of the model I’m assembling or image from the anime I am watching.

This is the Internet and I don’t mind people copying the images onto their website. I mean, why would I? Some of the images aren’t mine, like the Ubuntu logo. if I get an e-mail from Sunrise about a Gundam 00 image, I’d be shocked and flattered.

But I do not like hotlinking and had been blacklisting new URLs on a regular basis. Hotlinking is when some individual on the Internet decides he likes something on my website, so he loads it directly from my server onto his page.

Myspace users do that a lot.

So rather than continue looking at my logs and zapping offenders one at a time, I finally put in the following into my .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://blog.dembowski.net/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.dembowski.net/ [NC]
RewriteCond %{HTTP_REFERER} !^http://.*.google..*/ [NC]
RewriteCond %{HTTP_REFERER} !^http://.*.yahoo..*/ [NC]
RewriteCond %{HTTP_REFERER} !^http://.*.msn..*/ [NC]
RewriteRule .*.(gif|jpg|jpeg|png)$ - [F,NC]

This lets search engines that I like get copies of the images (I run a web server on the Internet, I want people to find me). The second line lets the web server load images if there is no referer.

If you try to load an images onto your website from my web server, and you are not on the approved list, then the image will not load. I thought about putting in a “Don’t hotlink you loser” image but why bother? I just want hotlink to my website to stop.