开发者

mod_rewrite different URIs to one location

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜