Reputation: 1404
I've been through plenty of docs but can't find the right rule on this case.
I have a single index.php file, containing a single iframe.php.
There is 3 optional parameters, although the first two have defaults if not specified. The parameters are passed to the iframe.
So I have
domain.com/?lang=en&country=us&game=myId
The iframe is called within the index like so :
<iframe src="iframe.php?lang=en&country=us&game=myId">
I would like the URL to be rewritten as :
domain.com/en-us/myId
without messing up the iframe parameters.
But
If the page is called without language parameters, the defaults are still set in the iframe, calling
domain.com
gives
<iframe src="iframe.php?lang=en&country=us">
In this case I would like the main URL to display
domain.com/en-us
Upvotes: 2
Views: 1224
Reputation: 143906
Try something like this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^$ /en-us [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})-([a-z]{2})(?:/(.*)|)$ /iframe.php?lang=$1&country=$2&game=$3 [L,QSA]
You then need to make sure you are constructing your URL's like:
domain.com/en-us/myId
and not use the query strings.
If you need to redirect the browser when accessing pages using query strings, include:
RewriteCond %{THE_REQUEST} \ /iframe.php\?lang=([a-z]{2})&country=([a-z]{2})(?:&([^&\ ]+))($|&|\ )
RewriteRule ^ /%1-%2/%3 [L,R=301]
To create separate rules for 2 and 3 parameters:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})-([a-z]{2})/(.+)$ /iframe.php?lang=$1&country=$2&game=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})-([a-z]{2})/?$ /iframe.php?lang=$1&country=$2 [L,QSA]
Upvotes: 2