views:

10

answers:

1

Hi guys,

I'm struggling with probably quite simple mod_rewrite taks.

This is the directory structure I have:

  • root\
    • translations\
      • en\ (contains various subfolders with files, 2 levels deep)
      • fr\ (contains various subfolders with files, 2 levels deep)

what I want to do is to point various dynamically created URLS to those specific locations without changing the URL in the address bar.

For example:

mydomain.com/one/ 
mydomain.com/two/ 
mydomain.com/three/

-> all would read content from /root/translations/en/index.php

mydomain.com/one/sub1/sub2/ 
mydomain.com/two/sub1/sub2/ 
mydomain.com/three/sub1/sub2/

-> would read content from /root/translations/en/sub1/sub2/index.php

mydomain.com/onefr/
mydomain.com/twofr/
mydomain.com/threefr/

-> all would read content from /root/translations/fr/index.php

mydomain.com/onefr/sub1/sub2/
mydomain.com/twofr/sub1/sub2/
mydomain.com/threefr/sub1/sub2/

-> would read content from /root/translations/fr/sub1/sub2/index.php

I tried something like:

RewriteCond %{REQUEST_URI} !\.css$ [NC]
RewriteRule ^/(one|two|three)/$ /_translations/en/ [L]

RewriteCond %{REQUEST_URI} !\.css$ [NC]
RewriteRule ^/(onefr|twofr|threefr)/$ /_translations/fr/ [L]

and while it works for the default redirect (e.g. mydomain.com/one/) the moment I want to go deeper it throws 404.

Any clues?

A: 

Try these rules:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^/(one|two|three)/(.*) /_translations/en/$2 [L]

RewriteRule ^/(one|two|three)fr/(.*) /_translations/fr/$2 [L]

The first rule will stop any request that can be mapped onto an existing file to be rewritten by any following rule. The other two rules are for the two cases you described.

Gumbo
That is exactly what I needed! Thank you!
criography