Reputation: 899
I tried all the solutions proposed in this site, but nothing worked.
This is what I did:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /folder/
RewriteRule ^([a-z]{2})$ index.php?lang=$1 [L]
RewriteRule ^([^/]*)$ index.php?page=$1 [L]
RewriteRule ^([a-z]{2})/([^/]*)$ index.php?lang=$1&page=$2 [L]
In essence, I want access the page in this format:
website.com/en
website.com/en/download
website.com/download
and translate to:
website.com/index.php?lang=en
website.com/index.php?lang=en&page=download
website.com/index.php?page=download
Any Solution?
Thanks.
Upvotes: 0
Views: 97
Reputation: 33813
I just tested the following rules on my dev server and they appear to achieve what you want.
RewriteBase /folder/
RewriteRule ^([a-zA-Z]{2})$ index.php?lang=$1 [NC,L]
RewriteRule ^([a-zA-Z]+)$ index.php?page=$1 [NC,L]
RewriteRule ^([a-z]{2})/([a-zA-Z]+)$ index.php?lang=$1&page=$2 [NC,L]
In the script /folder/index.php
for testing:
<?php
print_r($_GET);
?>
Example urls:
https://localhost/en/
-> Array ( [lang] => en )
https://localhost/download/
-> Array ( [page] => download )
https://localhost/en/download/
-> Array ( [lang] => en [page] => download )
Upvotes: 2
Reputation: 3202
Your first and last rules are just fine, but for the last option - a page without a language folder - you should simply redirect it to index.php and make sure there isn't another reiteration, in the following way
RewriteRule ^([a-z]{2})/(.*)$ index.php?lang=$1&page=$2 [L]
RewriteRule ^([a-z]{2})$ index.php?lang=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L]
Upvotes: 2