Forum Moderators: phranque

Message Too Old, No Replies

htaccess rewritecond - need some help

         

yayadk

9:46 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



Hi Guys..i am new here.
Hope you could help me.

I am running a site that uses a list of phrases in danish and makes them into links/url's (.htaccess).

I would like to know if someone could tell me what do i write in my .htaccess in order to change the url from danish letters to englisg letters.

Here is an example:
i have a phrase called - bro gårds vej
This phrase will need to like this: bro-gaards-vej
As you can see the letter å in danish can be written also in aa

Any help will be more then appriciated.

Yaya

jdMorgan

2:31 pm on Apr 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yaya,

Welcome to WebmasterWorld!

If you want to change the URL, do that on the pages themselves. Then use mod_rewrite to associate those URLs with the correct files or script calls on your server. More detail here [webmasterworld.com].

Using mod_rewrite in .htaccess to replace URL characters is very inefficient, and I cannot recommend it for busy sites. An acceptable approach is to use RewriteMap to call a script to do the character substitution, but this solution is only available in http.conf and conf.d file, and not in .htaccess.

As an example of how to do this in .htaccess, lets take a simple eaxmple:


RewriteRule ^(.*)a(.*)$ /$1b$2 [L]

That would change the first "a" to a "b".

I'm not sure if this will work for unicoded characters though. Assuming that the character code for å is %0229, you could try something like:


RewriteRule ^(.*)\%0229(.*)$ /$1aa$2 [L]

The problem is that you will need one line for each character to be converted, and that each line only converts a single instance of that character. So usually, the [N] flag is used on RewriteRule to re-start mod_rewrite processing so that all instances can be converted. But this is highly inefficient.

Jim

yayadk

2:53 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Jim.
Thanks for the help.

I am using mod_rewrite.

Right now i have this on my htaccess:
RewriteCond %{REQUEST_URI} ^(.*)\ (.*)$
RewriteRule ^.*$ %1-%2 [E=space_replacer:%1-%2]
RewriteCond %{ENV:space_replacer}!^$
RewriteCond %{ENV:space_replacer}!^.*\ .*$
RewriteRule ^.*$ %{ENV:space_replacer} [R=301,L]

It is taking a line with spaces and makes it into - instaed.
I would like to add to this a replacer for the danish chracters, so that in that sentaqnce which in being replaced with - instaed og space it will also replace the danish letters with the following:
å = aa
ø = oe
æ = ae

Anyway you could added to mine? i have no idea how to do it.

Thanks alot
Yair