Reputation: 8937
I created a .htacces file which does the following:
Redirects /
to /.index/
(visible in address bar)
or
Redirects /hu
or /en
to /.index/hu
or /.index/en
(visible in address bar)
Then
/.[p]/[l]
to /index.php?page=[p]&lang=[l]
(not visible in address bar)I want to preserve the query string at the end, which would mean visiting /.[p]/[l]?a=b
results in a request to /index.php?page=[p]&lang=[l]&a=b
I cannot seem to get the regular expressions working for this. Here's the whole .htaccess file:
RewriteEngine On
RewriteBase /Main/djdavid98/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(hu|en)?(\/?(\?(([\S]+\=[\S]+)*))?)?$ ./.index/$1$3 [R=301,L]
RewriteRule ^\.([\w\d]+)(\/(hu|en))?\/?(\?(([\S]*=[\S]*)+))?$ index.php?page=$1&lang=$3&$5
Upvotes: 1
Views: 44
Reputation: 143866
Use the QSA
flag for RewriteRule
which will append any query string that's already there to the end of the one you've constructed in your rule's target:
RewriteRule ^\.([\w\d]+)(\/(hu|en))?\/?(\?(([\S]*=[\S]*)+))?$ index.php?page=$1&lang=$3&$5 [L,QSA]
Note that query strings get appended to the end automatically, except when you've constructed your own in your rule's target. That's why the first rule will preserve the query string, but the second rule won't.
Upvotes: 1