.htaccess and rewrite of URL - .htaccess

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.

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.

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.

Related

Rewrite url to remove gclid query

I am trying to remove google's gclid tracking parameter from my urls. After searching around the internet it appears that I need to use url rewriting to solve the problem.
I am using IIS6 as a server so rather than .htaccess I am using isapi rewrite filter which is supposed to work the same way.
Ideally I would like to make this:
http://www.example.com/default.asp?parameter=stufftokeep&gclid=alotofrandomstuff
Become this:
http://www.example.com/default.asp?parameter=stufftokeep
no matter what comes after "gclid"
I was able to find this here on SO but replacing "tag" with "gclid" did not work, and keeps breaking the page.
Has anyone run into this issue with gclid parameter before who might be able to offer a solution?
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)(?:^|&)gclid=[^&]+(&.*)?$
RewriteRule ^(.*)$ /$1?%1%2 [L,R=301,NE]
In case anyone else has this issue with gclid parameter on IIS6 server using isapi rewrite filter v2 here is the code that solved the issue.
RewriteRule ^/([^?]+)\?(.*)(?:^|&)gclid\=[^&]+(\&.*)?$ /$1\?$2$3 [I,RP,L]

Is possible redirecting without change the url in .htaccess?

I have this url:
http://localhost/search/
This returns me this file:
http://localhost/search.html
Now I want the urls with this structure:
http://localhost/search/([^/]+)/([^/]+)/([^/]+)/?
will redirect me to the search.html file too. But without changing the url.
For example with this urls:
http://localhost/search/women/23/shoes/
http://localhost/search/
http://localhost/search/man/45/shirt/
would return the same file:
http://localhost/search.html
Note: the urls of man and women does not has any existing path in the server.
Any advice or help would be appreciated. If you need more info, let me know and I'll edit the post.
RewriteEngine on
RewriteRule ^search/ /search.html
Will just work fine. Unless you explicitly request an external redirect, a RewriteRule on the same domain will not do one, thus not changing the URL visible in the browser.
if you don't need the rest of url then you can use this
RewriteEngine On
RewriteRule ^search/(.*)$ /search.html [L]
if you need to other parameters of url then let me know
edited version, Niels Keurentjes has a point if you don't need the rest of url
RewriteEngine On
RewriteRule ^search /search.html

Subdomain redirect to URL Parameter while keeping other url params intact

I've looked like crazy for an answer to this - and I haven't been able to find one as of yet. My apologies in advance if I've missed something.
I'm looking to convert a subdomain to a url parameter while maintaining the other url pieces.
Such as:
http://sub.domain.tv/value redirects to http://domain.tv/value?campus=sub
This is what I've tried after looking through numerous posts on here:
# campus
RewriteCond %{HTTP_HOST} ^sub.domain.tv$ [NC]
RewriteRule ^(.*)$ http://domain.tv/$1/?campus=sub [R=301,L]
which worked fine for redirecting sub.domain.tv to domain.tv?campus=sub, but does not work with the rest of the URL parameters (so heading to sub.domain.tv/value does nothing).
I've tried other examples with the %1 and $1 being used as variables, such as with this post:
htaccess subdomain redirct with last url parameter but I don't understand the difference (and the examples I've tried did not work).
Thanks for taking a look! :) I very much appreciate it!
Have you tried the [QSA] parameter. This will add any remaining Query parameters to campus=sub

URL Rewriting subdomain

I'll be quick on what im trying to do,
basically I have a user profile page that will be my url, let's say,
profile.php?user=alex
So now what is working fine in my .htaccess file is changing that into
website.com/alex
for quicker access.
For other purpose, I would need that to be basically
alex.website.com
but I couldnt figure out a way to rewrite my URL to that, instead of having a subdomain for every user.
If you have any idea if it's possible & how I would go on doing this, I would appreciate it alot!
Thank you
Alex
To just rewrite the URL path, try this rule:
RewriteRule ^[a-z]+$ profile.php?user=$0
If your user names have a different syntax, replace [a-z] as you need.
For rewriting the host, try this rule:
RewriteCond %{HTTP_HOST} ^([a-z]+)\.example\.com$
RewriteRule ^$ profile.php?user=%1
Note that this will only rewrite //alex.example.com/ internally to //alex.example.com/profile.php?user=alex. Additionally, your server will already need to be configured that it accepts any subdomain of your domain (see ServerAlias and name-based virtual hosts).

subdomains pointing subfolders with mod rewrite

Hi I'm quite new to PHP... And need something to do as fast as I can..
I have some clients within the "clients" directory like here...
"http://domain.com/clients/client0001/fluids/..."
I want this URL to be shown in the address bar like this.
"http://client0001.domain.com/fluids/..."
with the help of .htaccess. Any help will be appreciated ...
Thanks
You can use mod_rewrite to rewrite such URLs:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^./]+)\.example\.com$
RewriteRule !^clients/ clients/%1%{REQUEST_URI} [L]
But your webserver needs to be configured so that it accepts such host names and sends the requests to the proper virtual host.
I've used this before as posted by Gumbo.
Only issue I've had with it is that you can't then use further rewrite rules - so if the site you are serving on the subdomain uses url rewriting, you have to make it its own virtual host.

Resources