Hide real URL with ISAPI Rewrite? - url-rewriting

Is it possible to hide real URL with HeliconTech's ISAPI Rewrite module? To be more specific, consider the following scenario:
User requests an URL "example.com/something".
"In the background", server redirects the request to another URL "anotherexample.com".
Contents from "anotherexample.com" are returned to the user (user still sees "example.com/something" in his/her browser address bar after response has been received).
So, the user must not be aware of the fact that contents came from different URL. If this isn't possible with ISAPI Rewrite, do there exist another ways to implement the functionality (in IIS 6 + SharePoint 2007 environment)?

This is achieved using proxy functionality in ISAPI_Rewrite 3. Here are the rules to put in .htaccess in the root of example.com site:
RewriteBase /
RewriteRule ^(.*)$ http://www.anotherexample.com/$1 [P]

Related

Redirecting from one domain to another with mod_rewrite

I've set up a site for someone that has a URL like:
www.flowers-oakville.com.
But they'd also like www.flowersoakville.com to land on the page.
The question now is, what is the best way to redirect from www.flowesoakville.com to www.flowers-oakville.com. I don't want the user's browser to show the redirection by showing the new URL in the address bar so I think Apache's Redirect command is not the solution. Plus, the Apache Redirect would take an extra trip to the browser and back that I'd like to avoid. So I think the solution needs to be a mod_rewrite, which as I understand it, does everything within the server so the round trip is avoided and the user's address bar is unchanged.
But after reading through a few mod_rewrite tutorials, it seems that mod_rewrite is mainly for redirecting files, not an entire website. Is there a simple way to do this?
Thanks for any help.
I would do this at the domain level and ensure you are using relative links or an environment variable for the hostname in the website.
Add www.flowersoakville.com as a CNAME record pointing to www.flowers-oakville.com.
This will then serve the same website, but retain the domain name as the user entered it, unless you have explicitly linked the actual domain in a link somewhere in the site.
If mode_proxy
is enabled on your server, you can use mod_rewrite (the following code) in your .htaccess file to redirect a domain to another domain without changing url in the address bar.
Try adding this to www.flowersoakville.com/.htaccess file :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?flowersoakville\.com$ [NC]
RewriteRule ^ http://www.flowers-oakville.com%{REQUEST_URI} [L,NE,P]
Note : The example above will not work if proxy module is not enabled on your server.
I wanted to pass on my experience trying to use Dwev's answer. It turns out that the DNS Manager running in my virtual server (I'm using eApps as my hosting provider) does not support "domain based redirection." That is, the left side of a CNAME record has to be in that domain. So when trying to build a CNAME record in the flowers-oakville.com record that points to flowers-oakville.com, the left side has to be xxx.flowers-oakville.com where the xxx might be something like www. I can't get the left side to be flowersoakville.com, even though flowersoakville.com is one of the domains my server is listening for.

RewriteHeader - Helicon ISAPI Redirect Old URL

There are instructions in the Helicon documentation on using the RewriteHeader http://www.isapirewrite.com/docs/#RewriteHeader and even one example which does exactly what I am looking for:
And this rule will add Old-URL header to the request, providing a Request-URL as a header value:
RewriteCond URL (.*)
RewriteHeader Old-URL: ^$ $1
I've added these two lines as the first two lines of my httpd.ini, stopped and started my website, recycled my application pool (neither of which should be required)... but I can't see any Old-URL header anywhere. I have been going to various URLs, ones with or without redirection rules and haven't been able to find the header. I have been using Chrome's Network tab to review the pages coming back from the server (with status of 301 and 200 respectively)
All redirects in the file are working fine.
Update: There are multiple ways redirects can happen in our current project and I want to add HTTP headers so I can see which method the redirect was fired from.
Try to fix the rule like this:
RewriteCond URL (.*)
RewriteHeader Old-URL: .* $1
Or consider using ISAPI_Rewrite 3 which is more straightforward and has logging to easier debug the problem.

Apache Redirect on downstream 404

We are building a mobile site whose url structure matches our current desktop site. We are hosting them on the same domain, and using apache to filter traffic between them using WURFL to help decide which agents go where.
Our filtering rules currently look like this:
RewriteCond %{HTTP_COOKIE} "bucket=mobile"
RewriteRule ^(.*)$ http://internal-mobile-pool.ourdomain.com/$1 [P]
RewriteRule ^(.*)$ http://internal-desktop-pool.ourdomain.com/$1 [P]
Our WURFL based solution sets the 'bucket' cookie for us.
The problem we are facing is that not all the urls on our desktop site have been re-implemented on our mobile site. What I would ideally like, is for the above rule to apply, but if it tries to go to the mobile servers, and gets a 404, it serves up the content from the desktop servers instead.
ie If a mobile requests www.ourdomain.com/some_desktop_only_resource.html, and the internal-mobile-pool.ourdomain.com/some_desktop_only_resource.html returns a 404 - for it to return the content on desktop-pool.ourdomain.com/some_desktop_only_resource.html
To describe this in pseudo-code
if(isMobile)
response = getMobileResponse(url)
if(response.code != 404)
serveResponse(response)
else
serveResponse(getDesktopResponse(url))
I know this is possible if I list all the supported urls in this file - I would like to avoid this, as I would like this Platform Recognition layer to be independent of the application it serves. I also know I could solve this in the mobile application itself by redirecting from there, but if at all possible, I would like this Platform Recognition layer to be self-contained.
Is this possible using mod_rewrite?
Don't think there's a way to do this using mod_rewrite. Because you're using the [P] flag to proxy, the RewriteRule hands the proxy request to mod_proxy and doesn't even know if it went through or not. If everything was in the same document root (or at least subdirectories of the document root), you'd be able to use the -f conditional check to see if a file exists.
Something you could try doing, though I have no idea if this will work, is using mod_proxy's ProxyErrorOverride along with ErrorDocument. If your ProxyErrorOverride is turned on, theoretically if a proxied request returns an error, mod_proxy will use the local error handler instead of the proxied one. You could then use a ErrorDocument 404 to handle the proxied 404 with a php script or something, then do something about re-routing it back through the local rewrite engine (with maybe a redirect with a special query string param?) so that it could be proxied to the desktop domain.

mod_rewrite one url to another url without changing source url

Is it possible to do a mod_rewrite from one url to another without changing what appears in the address bar?
Example:
Source URL is http://domain1.com/news
Target URL is http://domain2.com/news
I want to render pages from http://domain2.com/news/ but have http://domain1.com/news appear in the address bar.
Is this possible?
I've got this directive, but the URL in the address bar changes (which I don't want to happen):
RewriteRule ^(.*)$ http://domain2.com/news/ [L,NC]
As far as I know, it cannot be done with just a mod_rewrite rule that rewrites one domain to another. The http:// prefix causes an external redirect, which is why you see it in your browser. The server at domain1 sends the redirect back to the browser and the browser has to re-request from domain2. To avoid this, the server at domain1 has to be able to retrieve data from domain2. If you control both servers, I've heard you can use mod_proxy to accomplish this, but I don't know the details.
For rules that do not go from one domain to another, the normal behavior of mod_rewrite will not cause the browser to change the URL unless you use the [R] flag.

Rewriting example.com/folder/path to example2.example.com/path

Actually the thing is that i'm having a sub domain (example.domain.com) which is redirected from other domain of a folder (www.domain/folder) . but need the rewrite rule for my sub domain which shows the url links for the main domain ie., www.domain/folder/path
i need to get as example.domain.com/path. Instead of getting the main domain path i need to expose the URL with sub domain path.
As far as I can tell, there are two ways to do what you are wanting. Both of them require significant extra overhead. Both are also likely to require example.domain.com to lie about who it is.
I wouldn't recommend either if you can avoid it, but.
Method #1
Set up a transparent proxy on www.domain.com/folder to show the contents from example.domain.com. If I recall correctly, this can be done with mod_proxy, but I don't remember how specifically.
Method #2
Set up a rewrite rule on www.domain.com/folder to redirect to example.domain.com. Then set up example.domain.com to either lie about who and where it is, or fix all links in pages on example.domain.com to explicitly go to http://www.domain.com/folder.
In the root .htaccess file on www.domain.com: (to redirect to the subdomain)
RewriteRule ^folder/(.*) http://example.domain.com/$1 [R, L]
Actually the subdomain is created from godaddy account and the maindomain/folder is in other hosting server... masking can be done in top address bar but when i hover through links the actual URL path is displayed in lower left corner of the browser....
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} {HTTP_HOST}[a-zA-Z0-9.-]mydomain/folder/(.)
RewriteRule ^/folder/(.*)$ http://abc.example.in/$1 [L,R=301]
Some one has mailed me the above rewrite rule but still the problem persists...
I have been working on this issue from couple of days and i came to conclusion that
1)From godaddy account i have created a subdomain and forwarded with masking to the actual IP address of the virtual host server, but here comes the problem...
i could not forward to the (domainname/foder) rather i can do it for domainname
So i stuck up here for the solution
If u find a solution i would be considered them as a GENIUS......

Resources