Redirect URL

How can I redirect domain to a different domain?

For example, if ****something/anything&r=%2Ftitle loads, auto redirect to ****something/anything&r=%2Ftitle

I if siteA tried to load content, replace siteA with siteB and load the content. Everything after .com/ could change.

I have the following partially working:

on run
	tell application "Safari" to launch
end run

on idle
	if application "Safari" is not running then quit me
	tell application "Safari" to tell window 1
			set tnet to (tabs whose URL starts with "")
			delay 0.1
			if tnet is not {} then
				set URL of item 1 of tnet to ""
			end if
		end try
	end tell
	if application "Safari" is not running then quit me
	return 0.5
end idle

on quit
	continue quit -- allows the script to quit
end quit

To really make this work, I also need to have the script change/replace just the root domain, and keep everything after .com/ maybe using some sort of wildcard regex type approach?

Or, I need to get everything after .com/, copy it, and then append it to the redirect URL?

Note to anyone playing with this idea, the AppleScript must be saved as an Application. Also, in Safari, Developer Mode must be enables via Preferences > Advanced. Then in Safari, go to Develop (menu) > All JavaScript from Apple Events to turn it on.

I use the Requestly browser extension for this.

Thank you for the suggestion @BoulderRocks, but the solution needs to work in Safari too.

To make it work in Keyboard Maestro, or AppleScript, I need to:

  1. Create a variable to store the part of the URL I want to keep - everything after ".com/"
  2. Prepend the variable with the URL I want instead

I'm just not sure how to tell AppleScript to do this.

No need for AppleScript for this. Just replace the test URLs from your sample script with the actual ones where appropriate and this should do the trick in Safari, Chrome, and other KM9 supported browsers:

Auto Redirect URL.kmmacros (2.7 KB)

For best results, I recommend moving this macro to a macro group that's only active for the browsers you use.

1 Like

Thank you, I am giving this a try today. The URL that I need to redirect to has a lot of junk in it.

For example, the email button links to:

The page I need to get to is this URL:

That is a Single Sign On form by Pulse, that I have to log in to, then I can access the page.

Lots of room for error, but I am going to keep chipping away at this.

Thank you for the reply @gglick.

The previous attempts to use Keyboard Maestro to solve this problem did not work, so I am thinking maybe there is another way.


  1. I click a link in a corporate email.

  2. The link brings me to this login form at this URL

  3. I then have to click on "Use: Single Sign on Access »" button (see code below if that helps), which uses this link ""

  4. When that linked-top page renders, this is the URL.

Code for 'Use: Single Sign on Access »' button:
<a href="/saml.redirect?relayState=" class="ig-button_flat ig-button_flat_gray" id="samlsignin-submit-button">Use: Single Sign on Access »</a>

I think that all I really need to do is auto-redirect from "" to "" which I am trying today.

Wanted to provide an update in case it helps someone (or me) in the future.

The Keyboard Maestro solution (see below) works if I click the "Try" button in KM, however it does not work when Safari tries to access the initial URL.

For example, if I click a button in a corporate email, Safari opens "," but the redirect never gets triggered.

This is a screenshot from Keyboard Maestro:

In Safari, this is what happens:
Screen Shot 2021-02-20 at 11.22.34 AM

Focus goes to the Email Address field, which triggers 1Password's UI to auto fill the form.

I don't think this simple redirect is the solution - I think we still need the more complex solution I proposed.

In the corporate email, there is a button, on :hover we can see the link:

Clicking the button DOES NOT GO TO ""

Instead, I am taken to:

The way I am approaching it is that there are two variables in the URL - one is constant, the other changes every time there is a new email.



I need Keyboard Maestro to take the CONSTANT and append the VARIALBE when redirecting, or at least that is what seems to be necessary?

I cannot figure out how to get this working.