Reputation: 745
I have multiple domain extensions and have therefore written a mod_rewrite that takes rewrites the URL back to a .com setting the original extension as a query parameter:
RewriteCond %{HTTP_HOST} ^api\.example\.(co\.)?(.*)$
RewriteCond %{HTTP_HOST} !^api\.example\.com$
RewriteRule ^(.*)$ http://api.example.com/$1?l=%2 [QSA,R]
This works fine, my problem is that I need the internal redirect to be always to api.example.com/index.php
so that for instance:
api.example.fr/v1/users =>
(ext) api.example.com/v1/users/?l=fr
(int) api.example.com/index.php
I've been messing about with this for some time now and would appreciate any help on the matter...
Many Regards
Upvotes: 1
Views: 161
Reputation: 785256
Assuming DOCUMENT_ROOT
for api.example.fr
and api.example.com
are same.
You can have your code like this:
RewriteCond %{HTTP_HOST} ^api\.example\.(co\.)?(.*)$
RewriteCond %{HTTP_HOST} !^api\.example\.com$
RewriteRule ^(.*)$ http://api.example.com/$1?l=%2 [QSA,R,L]
# add missing /v1/ if needed
RewriteCond $1 !=index.php
RewriteRule ^((?!v1/).*)$ /v1/$1 [R,L,NC]
RewriteCond %{HTTP_HOST} ^api\.example\.com$
RewriteRule ^(?!index\.php) /index.php [L,NC]
Upvotes: 1