Forum Moderators: phranque

Message Too Old, No Replies

fr.example.com rewriting

Please help, I gave up.

         

tata668

1:49 am on Oct 13, 2007 (gmt 0)

10+ Year Member



Damn, I'm not good with mod_rewrite!

I try to convert:
fr.domain.com
to
domain.com/lang/fr

I tried:


RewriteCond %{HTTP_HOST} ^fr\.example\.com$
RewriteRule ^(.*)$ $1/lang/fr [L]

But it doesn't work. Note that I also have another rewriting rule to point everything to my main controller:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}!\.(gif¦jpg¦jpeg¦png¦swf)$
RewriteRule ^(.*) index.php

I'm trying to make them working together.

Any help will be really appreciated!

[edited by: jdMorgan at 1:54 am (utc) on Oct. 13, 2007]
[edit reason] example.com [/edit]

jdMorgan

11:55 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the rules are in the order shown above, then you may want to remove the [L] flag from the first rule. Otherwise, the second rule will never be applied to the "fr" subdomains.

You will also need to explicitly prevent recursion if this code is located in .htaccess:


RewriteCond %{HTTP_HOST} ^fr\.example\.com
RewriteCond $1 !lang/fr
RewriteRule (.*) $1/lang/fr
#
RewriteCond %{REQUEST_URI} !\.(gif¦jpe?g¦png¦swf)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php [L]

I also modified the order of the RewriteConds in the second rule, making it *much* more efficient. By palcing the filetype check first, you avoid doing 'file exists' and 'directory exists' checks for all image file requests -- Since the 'exists' checks invoke an 'expensive' call to the filesystem manager, they must be avoided if possible.

Note also that the pattern was modified to combine "jpg" and "jpeg" into the equivalent "jpe?g".

I made a few additional minor corrections/optimizations as well.

Replace all broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

tata668

12:08 am on Oct 17, 2007 (gmt 0)

10+ Year Member



Thanks a lot jdMorgan!

I'm gonna try that soon.