Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite not matching the whole url

mod_rewrite not working

         

cdsuze

9:38 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Hi guys, I'm using mod_rewrite to handle my multilingual site so things like this:

[my.site...]
[my.site...]

Are rewritten to (respectively):

[my.site...]
[my.site...]

I'm trying this:

RewriteRule ^(..)/([^\?]+)\?(.*)$ /$2?language=$1 [NC,L]

But it's not working. When I see the Rewrite Log, it shows up the following:

(3) [per-dir /home/mysite/public_html/] applying pattern '^(..)/([^\?]+)\?(.*)$' to uri 'en/index.php'
(1) [per-dir /home/mysite/public_html/] pass through /home/mysite/public_html/en

It doesn't match but it's showing an URI without the complete query string. I tryied to replace [NC,L] for [QSA] but still not working.

Does anybody know what I'm missing here?

Best regards

cdsuze

10:54 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



Sorry guys, I found the answer in the forum archives. I have to forget about query_string because the rewrite_rule only matches URI

I've done this:

RewriteRule ^(..)/(.*)$ /$2?language=$1 [QSA,L]

And it works ok. It strips the first two letters and appends the variable at the end of the query_string

Another question..i'm trying to handle uRL that ends with the two letter (without "/") and it's not working:

RewriteRule ^(..)[/]?(.*)$ /$2?language=$1 [QSA,L]

Is there a way to have it in only one rewrite_rule? or I have to add this one:

RewriteRule ^(..)$ ?language=$1 [QSA,L]

Best regards and thanks

César Enrique

jdMorgan

1:42 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



César,

Welcome to WebmasterWorld!

You can access the query string by using

RewriteCond %{QUERY_STRING} ^language=([a-z]{2})$

just as an example. The value of the 'language' parameter would then be available to the RewriteRule as variable %1

Jim

cdsuze

11:54 am on Jan 13, 2006 (gmt 0)

10+ Year Member




Thanks JdMorgan, didn't know that one ;)

César Enrqiue