tags:

views:

30

answers:

1

I have this mod-rewrite in my htacces which enables some clean urls;

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|nl)-?()?\/(.*\/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end

### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ ./index.php?symphony-page=$1&%{QUERY_STRING}  [L]

</IfModule>

Now I would like to also force www, so I extended the code:

<IfModule mod_rewrite.c>

RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteBase /

### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|nl)-?()?\/(.*\/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end

### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ ./index.php?symphony-page=$1&%{QUERY_STRING}  [L]

</IfModule>

However this results in none of my pages being found. FYI A language redirect adds country-code parameters to the url on load.

How do I get these rules to play along?

A: 

You're probably missing the query string:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [QSA,L,R=301]

You can also use the QSA flag in your other rules, e.g.:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ ./index.php?symphony-page=$1  [L,QSA,B]

I also added B because you're using the backreference in a query string, so it needs to be escaped.

See the documentation.

Artefacto