Reputation: 311
I have seen multiple similar questions in SO already, but never specific enough to solve my problem, or not even close to what I really want to achieve. In short:
I have a multi-language website www.domain.com
If I go to the "contact" page, it will change to www.domain.com/contact
My HTACCESS changes this to www.domain.com?page=contact
When I enter a subpage on the contact page, let's say "manager" it changes to www.domain.com/contact/manager
which HTACCESS changes to www.domain.com?page=contact&subpage=manager
This is working all fine. But now I want to implement languages. Here is what i want to achieve:
<if first parameter = (EN|FR|DE enz)> <-- HOW?
RewriteRule ^([a-zA-Z]+)/*([a-zA-Z0-9\-]+)/*([a-zA-Z0-9\-]+)/*$
index.php?lang=$1&page=$2&subpage=$3 [QSA,L]
</if>
<else>
RewriteRule ^([a-zA-Z0-9\-]+)/*([a-zA-Z0-9\-]+)/*([a-zA-Z0-9\-]+)/*$
index.php?page=$1&subpage=$2 [QSA,L]
</else>
How should the first line be? No tutorial helped. I am a noob in HTACCESS, which might explain why I can't find a fitting solution. Thanks in advance :)
Upvotes: 1
Views: 111
Reputation: 785156
You can use separates rules like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([a-z]{2})/([\w-]+)/([\w-]+)/?$ index.php?lang=$1&page=$2&subpage=$3 [QSA,L,NC]
RewriteRule ^([a-z]{2})/([\w-]+)/?$ index.php?lang=$1&page=$2 [QSA,L,NC]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?page=$1&subpage=$2 [QSA,L]
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [QSA,L]
Upvotes: 1