Forum Moderators: phranque

Message Too Old, No Replies

Language sub domains and multiple directories

         

AceRimmer

1:49 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



Hi, Im having trouble getting my language sub domains to allow multiple directory selection aswell.

I want to do the following:

en.example.com
en.example.com/forum/
en.example.com/login/

index.php?language=en
index.php?language=en&page=forum
index.php?language=en&page=login

The same for each language. The index page uses the language sub domain, but I also want to use the directory.

Code:

RewriteCond %{HTTP_HOST} ^(de¦en¦fr¦ger¦it¦es)\.example\.com$
RewriteRule ^$ /index.php?language=%1
RewriteRule ^forum/ /index.php?page=forum&language=%1
RewriteRule ^login/ /index.php?page=login&language=%1

it either does the language or the page how can I make it return both page and language

Help would be greatly appreciated.

jdMorgan

4:59 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ace,

Welcome to WebmasterWorld!

Aside from a few recommended minor syntax tweaks, I think the main problem here is that a RewriteCond applies only to the single RewriteRule that follows it. Therefore, %1 is undefined for your second and third RewriteRules.

Does that help?

Jim

AceRimmer

7:13 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



Thanks for the reply. How can I make the rewritecond accesible by all the rewrite conditions then, so %1 is accesible in each rewriterule?.

Or can two rewriterules be used? the first setting the language

RewriteCond %{HTTP_HOST} ^(de¦en¦fr¦ger¦it¦es)\.example\.com$
RewriteRule ^$ /index.php?language=%1

and another for getting the directory?

AceRimmer

7:55 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



Abit more expermenting and ive got it working in sorts.

RewriteCond %{HTTP_HOST} ^(de¦en¦fr¦ger¦it¦es)\.example\.com$
RewriteRule ^(¦forum/¦login/)$ /index.php?language=%1&page=$1 [L]

Is that a valid rule?

[edited by: AceRimmer at 7:56 pm (utc) on Mar. 17, 2005]

sitz

7:55 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



Not trying to jump in while someone else is helping already, but it's been a few hours. If index.php Does The Right Thing(tm) if it's passed an empty 'page' value, why not this:

RewriteCond %{HTTP_HOST} ^(de¦en¦fr¦ger¦it¦es)\.example\.com$ [NC]
RewriteRule ^/($¦index.php)¦(forum¦login)/(index.php)? /index.php?page=$2&language=%1 [L]

(seems a little ugly; I'd be interesting in seeing if there's a better solution to this)

The downside to the above, is that it doesn't fully deal with mixed/upper-case Host: headers correctly. If you can handle that at the application, that's fine. If not, you'll need to augment to:


RewriteMap tolower int:tolower
RewriteCond %{HTTP_HOST} ^(de¦en¦fr¦ger¦it¦es)\.example\.com$ [NC]
RewriteRule ^/($¦index.php)¦(forum¦login)/(index.php)? /index.php?page=$2&language=${tolower:%1} [L]

AceRimmer

8:00 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



Thinking ahead, what about if I wanted to do a more complicated rule?

Say I wanted to use /articles/110/ does this mean I have to have the same rewritecond again to do each of these more complex rewrite rules?

Thanks for the 2nd reply Ill give that a try.

sitz

9:36 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Depends on what you mean, really. Are you looking to replace the rewriting mentioned above with something else, or do you want the rules discussed above to apply site-wide?

AceRimmer

7:39 pm on Mar 19, 2005 (gmt 0)

10+ Year Member



I'd like the

RewriteCond %{HTTP_HOST} ^(de¦en¦fr¦ger¦it¦es)\.example\.com$ [NC]

to apply to all the rules.

The problem with the Rewriterule is it only takes the language and page paramaters.

If I wanted another rule which took more paramaters, say an article id, page and language, and passed that to the index page the above rules wouldnt work.

But the article will only apply to one rule so I cant pass it everytime to the above rule.