ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

trouble with mod rewrite for multilingual + multiple countries site

April 04, 2012 2:56pm

Subscribe [3]
  • #1 / Apr 04, 2012 2:56pm

    garda

    35 posts

    This is not really specific to expression engine, but i’m trying to get mod rewrite to work, I’m starting from the official mod. I’m using the transcribe plugin, which is adding the language code to the url, but i’d like to have the country code too.

    The current format of the urls is:
    /en/us-news/article

    I would like to change it to:
    /us/en/news/article

    Seems pretty simple, this regex should take care of it:

    RewriteRule ^/index\.php/(ca|us)/(en|fr)/([^/]*)(.*)$ /index.php/$2/$1-$3$4 [L]

    But the urls aren’t rewritten properly.. This test url:
    /us/en/news/article
    Becomes:
    /index.php/en/us-news/article/en/news/article

    The variables contain:
    $1:  en
    $2:  us
    $3:  news
    $4: /article/en/news/article

    It’s $4 that’s the problem. It should only contain “/article” but a half-rewritten url is appended to the end of the variable. I have no clue where this comes from, could it be that apache parses the regex in several steps, making the replacements as it goes?
    How could i make this work? What other process could be interfering?


    The full .htaccess:

    <IfModule mod_rewrite.c>
            RewriteEngine On
      
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            #RewriteRule ^(.*)$ /index.php/$1 [L]
            RewriteRule ^(.*)$ /index.php/$1 [C]
      
     RewriteRule ^/index\.php/(ca|us)/(en|fr)/([^/]*)(.*)$ /index.php/$2/$1-$3$4 [L] 
    
            # If 404s, "No Input File" or every URL returns the same thing
            # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    Thanks,

    Vincent

  • #2 / Apr 04, 2012 3:25pm

    glenndavisgroup

    436 posts

    Hi Vincent,

    Try the following:

    <IfModule mod_rewrite.c>
            RewriteEngine On
            
            RewriteRule ^/index\.php/(ca|us)/(en|fr)/([^/]*)(.*)$ /index.php/$2/$1-$3$4 [L] 
      
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            #RewriteRule ^(.*)$ /index.php/$1 [L]
            RewriteRule ^(.*)$ /index.php/$1 [C]
      
    
            # If 404s, "No Input File" or every URL returns the same thing
            # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    Mike

  • #3 / Apr 05, 2012 11:05am

    garda

    35 posts

    Just tried a few versions with the rewriterule on top, i get different errors but it still doesn’t work.. :(

  • #4 / Apr 05, 2012 11:06am

    Shane Eckert

    7174 posts

    Hello garda,

    Thank you for posting your question here on the ExpressionEngine forums.

    Have you had a chance to try our Mike’s suggestion?

    I can also move this over to the Community Help Forum if you would like? The community might be able to help you come up with something that works if the above does not.

    Cheers,

  • #5 / Apr 05, 2012 11:35am

    garda

    35 posts

    Making some progress, I’m testing with a redirect to see the resulting url, and this works:

    RewriteRule /(ca|us)/(en|fr)/([^/]*)(.*)$ /index.php/$2/$1-$3$4 [R=307,L]

    But as soon as I remove the redirect, i get a blank page

    This is the closest i got, the only problem is that it rewrites the url in the browser bar. When I remove the R flag, i get a blank page:

    <IfModule mod_rewrite.c>
            RewriteEngine On
    
            RewriteRule /(ca|us)/(en|fr)/([^/]*)(.*)$ /index.php/$2/$1-$3$4 [R=307,L]   
        
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
      
    </IfModule>

     

     

  • #6 / Apr 05, 2012 11:37am

    garda

    35 posts

    Hi Shane, yes you can move the post, thanks!

  • #7 / Apr 09, 2012 10:53am

    garda

    35 posts

    Well it turns out the culprit wasn’t the rewrite regex; it’s a config settings that needs to be set in expression engine.. In system/expressionengine/config/config.php, the ‘uri_protocol’ var must be set to ‘PATH_INFO’:

    $config['uri_protocol'] = 'PATH_INFO';

    And now, EE parses the rewritten url and the correct page shows up!

    Vincent

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases