Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect and Redirect from URL with Anchor Using mod_rewrite/htaccess?

I've seen a number of examples of the opposite, but I'm looking to go from an anchor/hash URL to a non-anchor URL, like so:

From: http://old.swfaddress-site.com/#/page/name
To:   http://new.html-site.com/page/name

None of the examples at http://karoshiethos.com/2008/07/25/handling-urlencoded-swfaddress-links-with-mod_rewrite/ have functioned for me. It sounds like REQUEST_URI has the /#/stuff in it, but neither me nor my Apache (2.0.54) see it.

Any ideas, past experiences or successes?

like image 298
Metric Scantlings Avatar asked Aug 04 '10 18:08

Metric Scantlings


3 Answers

Anything after the # is a fragment, and will not be sent to the webserver. You cannot capture it at any point there, you'll have to use a client-sided approach to capture those.

like image 190
Wrikken Avatar answered Nov 20 '22 05:11

Wrikken


@RobRuchte : would it not be better to use window.location.hash, with a replace instead of a regular expression?

var redirectFragment = window.location.hash.replace(/^#/,'');
if ( '' !== redirectFragment ) {
    window.location = 'http://new.html-site.com' + redirectFragment;
}
like image 40
m14t Avatar answered Nov 20 '22 05:11

m14t


I'm the author of the post you linked to. Wrikken is correct, the content after the named anchor is not sent to the server unless something has mangled the URL along the way. On the client side, you need some JavaScript like this in your landing page to redirect the swfaddress links to corresponding URLs on another domain:

var re = new RegExp('#(.*)');
var redirectFragment = re.exec(document.location.toString());
if (redirectFragment!=null)
{
    document.location = 'http://new.html-site.com'+redirectFragment[1];
}
like image 1
Rob Ruchte Avatar answered Nov 20 '22 06:11

Rob Ruchte