Redirecting a Website request with multiple embedded URL strings - f5

I need to redirect the following example to a new website URL.
https://test.test.com/MDR/LauncherInterface.aspx?host=https://test.test.com/MDR&numid=11111&numid=1111&username=1111&userpass=1111
I need to redirect both URL statements to https://test2.test.com. Using iRules in my F5 load balancer I am able to redirect the first statement but I am unable to figure out how to redirect the second as well.

something like this should help:
when HTTP_REQUEST {
if { [HTTP::host] eq "test.test.com" } {
HTTP::redirect https://test2.test.com[HTTP::uri]
}
}
You can also do this with a local traffic policy, and if the rule is really this simple, that would be the preferred approach as it would be more performant. See this article on DevCentral for details on choosing iRules versus local traffic policy.
Finally, known that using the HTTP::redirect command, you'll be restricted to a 302. Use HTTP::respond to change the redirect code.

Related

How can I redirect to a particular view based on url in grails

I am using grails 2.5.5 version, Suppose I am entering url as www.localhost:8080/app-name then it should open the MyHome.gsp, suppose if I give other url ex: demo1.localhost.com:8080/app-name then it should redirect to some login page like login.jsp. How can I do that?
Let me break it up for you :
Suppose I have www.localhost:8080/app-name
suppose if I give other url ex: demo1.localhost.com:8080/app-name
Your app starts here:
Case 1 :/app-name
case 2 :/app-name
The rest of that url is actually DNS and configurating binding tomcat specific or wild card urls to a given application.
So in short you need to filter entire url in the application parse url and redirect in your app accordingly.
You need to then intercept every url with grails 2 there is SecurityFilters which so far as i know works with apache-shiro may also work with spring security.
and within it you need to overall check for something like
URL url = new URL(request.getRequestURL().toString())
String subdomain=url.host
if (subdomain.contains('.')) {
subdomain= subdomain.split('.')[0]
}
that then returns your `demo1` you then redirect it another url if it matches your specific rule.
But as I said you are talking about superficial stuff here as I expressed what the address is or how somone gets to the app has nothing to do with the actual application. This is why IT is big business. Big business not because everyone tries to narrow everything down into one box doing all of this but because when situations likes this happen bigger thinking is needed i.e. do i need a load balancer something like F5 that will split traffic according to a given url and send to another app container that asks for authorisation.
subdomain= subdomain.split('.')[1] in that case then but this leaves room for errors since user could put in demo1.somedomain.com and if that resolves well it is either split by subdomain= subdomain.split('.')[0]
I would do this then
String subdomain=url.host
if (subdomain.contains('.')) {
def splitter= subdomain.split('.')
subdomain= splitter[0]
if (subdomain=='www' && splitter.size()>1) {
subdomain= splitter[1]
}
}

How to do Soundcloud Auth Dance in JS with a Redirect_URL that has GET Params

** I am currently implementing fancy URLs to see if these 'solves' this. eg /me/soundcloudconnect rather than index.php?c=me&a=soundcloudconnect via mod_rewrite **
I have been using the Soundcloud JS SDK and SC.Connect() etc function(s) which automates much of the Auth process. I have been using a Normal html file: sc.html which worked fine and allowed me to get /me/ and /me/tracks etc.
However I now realise? that I will need to perform Auth myself as I need to add a State variable as documented below, so that it prepends these params to the end of the Redirect_URI.
http://groups.google.com/group/soundcloudapi/browse_thread/thread/7bddbc296f3b80af
The URL that I am trying to redirect back to is:
index.php?c=me&a=soundcloudconnect
which is the 'me' controller and 'soundcloudconnect' action.
So could someone please point me in the right direction?
Either I want to be able to use SC.Connect() etc (but also be able to get and save Token) as well as redirect back to the URI above
Or, I need to do the same thing (Auth and store token) but not using SC.Connect() but normal JS instead.
I read that Soundcloud Developer support is via Stackoverflow - so hopefully someone can help?
The normal HTML file with working SC Auth:
http://socialartist.co/sc.html
The dynamic page which does not work with SC Auth:
http://socialartist.co/index.php?c=me&a=soundcloudconnect#
The issue is probably that those query parameters are interfering with the original url. E.g. http://www.soundcloud.com/register/?token=blagha23412&redirect_uri=http://anydomain.com/index.php?c=me&a=soundcloudconnect
How would SoundCloud distinguish between your parameters and its parameters? You might be able to wrap the redirect_uri value in quotes.
An alternative might be to use the path as your parameters. E.g. http://anydomain.com/index.php/me/soundcloudconnect and then you should be able to grab whatever you need out of the path on your server.
** SOLVED!! **
If you need to pass parameters to SC connect/auth then the only way to do this is to setup fancy urls via mod_rewrite.
There 'seems' to be another method here, but you need to be doing the Auth in 2 steps and not via SC.Connect.
http://groups.google.com/group/soundcloudapi/browse_thread/thread/7bddbc296f3b80af
I was trying to get URL_redirect to work with:
index.php?c=me&a=soundcloudconnect
But in the End just used Fancy URLs which worked
http://socialartist.co/me/soundcloudconnect

Match full url in backbone

I'm looking for solution to invoke backbone action for particular route in my app.
I know that it's possible to match url like:
localhost:3000/#posts/1
But what if I need to match url like:
localhost:3000/posts/1
Opt-in to the new HTML history API / pushState, e.g.:
Backbone.history.start( { pushState : true } );
Depending on your application, you may want to take other steps as well, e.g.:
Note that using real URLs requires your web server to be able to correctly render those pages, so back-end changes are required as well.
http://backbonejs.org/#History

Best practice for redirecting from one web domain to another in Grails?

I am currently working on a filter in Grails that will allow me to redirect all incoming requests on foo.org to the same subpage on foo.com.
So far I have been doing the following:
if(!(""+request.requestURL).toLowerCase().startsWith(
grailsApplication.config.grails.serverURL ))
{redirect(url:"${grailsApplication.config.grails.serverURL}${request.requestURI}",params:params) }
Unfortunately, I am experiencing several issues in this approach:
The request.requestURI value seems to behave differently than expected: instead of giving me the normal "/[controller]/[action]" pattern as I would expect, it returns something like: "/grails/[controller]/[action].dispatch". - Is there an alternative way to obtain the "normal" URI? (excuse me if this is trivial, but have not been able to find it in the documentation, nor by trying out the various methods available on the request object)
Params are not being passed in the above redirect. This is probably due to the fact that I am using the "url" parameter in the redirect which according to the docs is supposed to be used for redirects to absolute paths (which again causes it to ignore the params section?). However, since I will not be able to use the normal redirect(controller:...,action:...) approach when redirecting to another domain what approach could I use in order to pass the params correctly along to the subpage on foo.com ? Am considering a solution where I will add the params manually via a params.each{} closure, but isn't there a more elegant solution to this?
301 redirects. Since my redirects are of a permanent nature, I would like to use the 301 status code. I have tried to set "response.status = 301" but it seems to be ignored when using the Grails redirect(...) method. Further I can see from grails.org that this seems to be introduced with grails 2.0, but is there a way to obtain this already now in Grails 1.3.7?
Use request.forwardURI.
If you have meant GET params, then it should be resolved using the above URI?
I think 301 redirects are not possible using classic redirect. You can do this in a filter like this, which is obviously not the cleanest way:
def filters = {
all(controller:'*', action:'*') {
before = {
if (request.serverName == "foo.org") {
response.setStatus(301);
response.setHeader("Location", "http://foo.com" + request.forwardURI)
response.flushBuffer()
return false; // return false, otherwise request is handled from controller
}
}
}
}

Redirect 301 with hash part (anchor) #

One of our website has URL like this : example.oursite.com. We decided to move our site with an URL like this www.oursite.com/example. To do this, we wrote a rewrite rule in our Apache server that redirect to our new URL with a code 301.
Many websites link to us with URLs of the form example.oursite.com/#id=23. The problem is that the redirection erase the hash part of the URL with IE. As far as I know, the hash part is never sent to the server.
I wanted to implement the redirection with javascript to keep the hash part, but the Search Engine will not be aware that our URL changed. (no code 301 returned)
I want the Search Engine to be notified of our new URL(301) because we need to transfer the page rank to our new URL.
Is there a way to redirect with a 301 code and keep the hash part(#id=23) of in the URL ?
Search engines do in fact care about hash tags, they frequently use them to highlight specific content on a page.
To the question, however, anchor locations are unfortunately not sent to the server as part of the HTTP request. If you want to redirect a user, you will need to do this in Javascript on the client side.
Good article: http://web.archive.org/web/20090508005814/http://www.mikeduncan.com/named-anchors-are-not-sent/
Seeing as the server will never see the # (ruling out 301 Redirects) and Google has deprecated their AJAX Crawling scheme, it seems that a front-end solution is the only way!
How I did it:
(function() {
var redirects = [
['#!/about', '/about'],
['#!/contact', '/contact'],
['#!/page-x', '/pageX']
]
for (var i=0; i<redirects.length; i++) {
if (window.location.hash == redirects[i][0]) {
window.location.replace(redirects[i][1]);
}
}
})();
I'm assuming that because Google crawlers do indeed execute Javascript, the new pages will be indexed properly.
I've put it in a <script> tag directly underneath the <title> tag, so that it get executed before any other JS/CSS. Note that this script should only be required for your index file.
I am fairly certain that the hash/page anchor/bookmark part of a URL is not indexed by search engines, and therefore has no effect on your page ranking. Doing a google search for "inurl:#" returns zero documents, so that backs up my assumption. Links from external sites will be indexed without the hash.
You are right in that the hash part isn't sent to the server, so as far as I am aware, there isn't a good way to be able to create a redirection url with the hash in it.
Because of this, it's up to the browser to correctly manage the hash during a redirect. Firefox 3.5 appears to do this successfully. If you append a hash to a URL that has a known redirect, you will see the URL change in the address bar to the new location, but the hash stays on there successfully.
Edit: In response to the comment below, if there isn't a hash sign in the external URL for the part you need, then it is entirely possible to rewrite the URL. An Apache rewrite rule would take care of it:
RewriteCond %{HTTP_HOST} !^exemple\.oursite\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.oursite.com/exemple/$1 [L,R]
If you're not using Apache, then you'll have to look into the server docs for something similar.
Google has a special syntax for AJAX applications that is based on hash URLs: http://code.google.com/web/ajaxcrawling/docs/getting-started.html
You could create a page on the old address that catches all requests and redirects to the new site with the correct address and code.
I did something like that, but it was in asp.net, which I guess it's not the language you use. Anyway there should be a way to do this in any language.
When returning status 301, your server is supposed to return a 'Location:' header which points to the new location. In practice, the way this is implemented varies; some servers provide the full URL (netloc and path), some just provide the new path and expect the browser to look for that path on the original netloc. It sounds like your rewrite rule is stripping the path.
An easy way to see what the returned Location header is, in the python shell:
>>> import httplib
>>> conn = httplib.HTTPConnection('exemple.oursite.com')
>>> conn.request('HEAD', '/')
>>> res = conn.getresponse()
>>> print res.getheader('location')
I'm afraid I don't know enough about mod_rewrite to tell you how to do the rewrite rule correctly, but this should give you an idea of what your server is actually telling clients to do.
The search bots don't care about hash tags. And if you are using them for some kind of flash or AJAX calls, you have more serious problems than your 301 redirects don't work. Because unless you have the content in an alternate form, the search engines are not indexing your site and you are definitely suffering as far as SEO goes.
I registered my account so I can't edit.
zombat : I'm sorry I made a mistake in my comment. The link to our video is exemple.oursite.com/#video_id=233. In this case, my rewrite rule in Apache doesn't work.
Nick Berardi: We changed the way our links work. We don't use # anymore, only for backward compatibility

Resources