full of … these

Rewrite rule without losing the initial URI

Posted: November 9th, 2012 | Author: | Filed under: howto, idiots | Tags: , , | No Comments »

Today, I had to add a rewrite rule to keep the short word (keyword) after “domain.com/”.

So, you want to keep the keyword in the address bar, but load the long URI and not showing it.

Here is my solution:

RewriteRule ^/(keyword-or-short-name)/?$ /long/i-mean-long-very-long-with-lots-of-params.htm

Happy users!


RewriteRules for special characters

Posted: November 18th, 2009 | Author: | Filed under: fun, howto, idiots, linux | Tags: , , , | No Comments »

Let’s say you have to write RewriteRules for special characters (East Asian Languages in this example, but, it should work for any other).

Link that you want to work: http://domain.tls/리눅스
Destination http://domain.tld/linux

First you must convert/encode (I used http://people.w3.org/rishida/scripts/uniview/conversion.php)
리눅스 is converted to %EB%A6%AC%EB%88%85%EC%8A%A4
You can get this from your access.log file of your server if you access it.
Now, you have to escape the % to match the regexp. Replace % with \x:

RewriteEngine On #add it in case it was not added above
ewriteCond %{HTTP_HOST} domain.tld
RewriteRule ^/\xEB\xA6\xAC\xEB\x88\x85\xEC\x8A\xA4$ http://http://domain.tld/linux

Restart or reload.
mod_rewrite should be loaded.
Debug: read /var/log/httpd/error.log and access.log (or corresponding error/access log file for the vhost you want the rule to be added.

Why sometimes RewriteRules don’t work

Posted: November 10th, 2009 | Author: | Filed under: howto, linux | Tags: , | No Comments »

I’m not an expert, but here is what you should check.

When you add a domain to be forwarded to a page on the same domain like this:
RewriteCond %{HTTP_HOST} domain-1.tld
RewriteRule ^/$ http://www.domain-1.tld/link/to/the/page/you/want/to/be/forwarded.htm [L]

And, after this you want another section named “section”of this site to be forwarded elsewhere, the other domain like this:
RewriteCond %{HTTP_HOST} domain-1.tld
RewriteRule ^/section$ http://www.domain-2.tld/link/to/a/section.htm

This will not work.
This will not work even if you want to escape the /section by placing it above the rewriterule for /.
This is happening because of the [L] from the first rewrite.
[L] Tells Apache to not process any more RewriteRules if this one was successful.

Now add [L] for /section and you are good to go.