views:

202

answers:

3

We have the following example "ugly" URL:

https://some.uglyurl.com/directory/test.jsp?hotelid=1111&rateplanid=33333

we need to direct our customers to the above URL using our own domains URL as the address - so it would look something like:

https://www.PrettyURL.com/reservations?hotelid=1111&rateplanid=33333

The idea being that the address our customers "see" is a nice looking "familiar" URL to them. Is this possible in .htaccess? We would tack on various variables AFTER the test.jsp in the ugly URL - so it can't just be a fixed set of variables.

many thanks for any help.

A: 

The Ultimate Guide to HTaccess

Phill Pafford
+2  A: 

If you were just using plain HTTP, you could set up the pretty URL server as a proxy that passes every request to the ugly URL server and the response back to the client:

RewriteCond %{HTTP_HOST} ^pretty\.example\.com$
RewriteRule ^reservations$ http://ugly.example.com/directory/test.jsp [L,P]

But as you’re using HTTPS, it is not possible without getting an error message, that the certificate’s host name is not correct.

Gumbo
Mo Boho
Do you modify the query of the URL? If so, add the QSA flag to get the original query automatically appended to the new URL.
Gumbo
not sure I understand, what is a "QSA flag". Sorry I'm bit of a noob with this! :) here is what I have:<br><br>RewriteCond %{HTTP_HOST} ^www.prettyurl.com$RewriteRule ^/reservations$ https://booking.uglyurl.com/istay/istay.jsp [L,P]
Mo Boho
The comma separated list in square brackets at the end of the directives is called flags. And if you want to use this rule in the .htaccess file in you document root, remove the leading slash of your patterns. That directory dependent slash is removed from the URL path before testing the patterns and added again after applying a rule.
Gumbo
Mo Boho
Gumbo
Did as you stated BUT it's still not accepting/carrying forward the 2nd set of variables (for whatever reason it discards it) - when we actually NEED them to be there. (btw...thank you so much for your help with this. :)
Mo Boho
Mo Boho
Then append it with `…?%{QUERY_STRING}` to the new address.
Gumbo
A: 

This is the code that worked for me:

RewriteCond %{HTTP_HOST} ^www.prettyurl.com$
RewriteRule ^reservations$ https://uglyURL.com/istay/istay.jsp?%2 [QSA,L]

It works exactly as I needed it.

Many thanks to Gumbo and others for all their help.

Mo Boho