Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule URLs

         

nimonogi

6:06 am on Oct 3, 2010 (gmt 0)

10+ Year Member



Hello,

I'm trying to create a rule that will rewrite URLs ending with "?language=gr" to a "/gr/" directory.

For Example:
1. domain.com/?language=gr to domain.com/gr/
2. domain.com/computers.php?language=gr to domain.com/gr/computers.php
3. domain.com/laptop/?language=gr to domain.com/gr/laptop/
4. domain.com/laptop/hp.php?language=gr to domain.com/gr/laptop/hp.php


I have created the following rule which works as i want to, except when it is in directories...

RewriteRule ^gr/([^/]*)$ ./$1?language=gr [L]

Working - domain.com/gr/
Working - domain.com/gr/computers.php
Not Working - domain.com/gr/laptop/netbooks/
Not Working - domain.com/gr/laptop/netbooks/hp.php

Thanks in advance.

sublime1

4:52 pm on Oct 3, 2010 (gmt 0)

10+ Year Member



nimonogi --

I am pretty sure I don't understand the first part of your question which seems to be the opposite of what you want -- but I am probably just misunderstanding what you write. If the following does not answer your question, please consider using full URLs and server paths. Also, while it appears that your rewrite rules are in the context of the server config or virtual host, please confirm that they are not in a .htaccess file

So starting from "I have created the following rule..." here's what I can say:

The rewrite rule you specify reads: for incoming URLs having paths starting with "gr/" and having 0 or more characters afterwards that are not a slash, perform an internal rewrite that takes all the characters after the gr/ and internally rewrite them to have a path under the current directory, adding a ?language=gr and serve that page.

So the reason the Not Working examples don't work is that they do have a slash after the "gr/"

Why not just


RewriteRule ^gr/(.*)$ ./$1?language=gr [L]


Tom