views:

60

answers:

2

I have this rewrite rule...

Redirect all initial request from world.example.com to web.example.com

RewriteCond %{HTTP_HOST} ^world\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^(.*)$ https://web.example.com$1 [R=301,L]

Which works great. But, some of my applications has...

https://world.example.com/approvals/?id=b47b5256567

Unfortunately, it is not being redirected properly to web.example.com. Instead, it just goes to web.example.com without the query params.

How could I make all request redirect properly to web.example.com along with the query params?

Basically, what it should do...

https://world.example.com/approvals/?id=b47b5256567
then
https://web.example.com/approvals/?id=b47b5256567

Just changing the world to web and passing the query string.

Help

+1  A: 

You forgot to use the "Query String Append" flag [R=301,L,QSA].

Havenard
Yeah, but the rewrite is a bit complicated.
Louie Miranda
Well, I don't think so. But of couse Greg Hewgill's suggestion is much more professional, assuming you have access to the server config files.
Havenard
+2  A: 

You don't need to use the complicated rewrite engine to do this. Just use Redirect:

<VirtualHost *>
    ServerName world.example.com
    Redirect permanent / https://web.example.com/
</VirtualHost>

The Redirect directive automatically preserves everything that comes after what you're redirecting.

Greg Hewgill
That's nice. Hold-on, let me try. Should I turn off the RewriteEngine Off also?
Louie Miranda
The RewriteEngine is not used by the Redirect directive, so it doesn't matter.
Greg Hewgill
Got it! It worked! But, only on http. If a https://world.example.com link was used, it just redirects to the main page without the query https://web.example.com.Not sure if this might just be me, but my world.example.com (is a self signed certificate), not sure if this is causing the problem.But, overall - the solutions fits easily. And thank you.
Louie Miranda
There may indeed be some odd interactions between http and https when using this. If that continues to be a problem, it could be a topic for another question. :)
Greg Hewgill