Redirecting with old URL?

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 9
Joined: 03 Oct 2012, 11:17

Redirecting with old URL?

26 Jan 2017, 14:10

Hi. I have a question. At work we have an old DNN implementation. We've moved away from it to Drupal, but there are still apparently people out there with bookmarks to the DNN. I had the idea to repoint the DNS for the old site's domain name to a "redirector" site I made. It's a small bit of PHP to shoot me an email with the original URL they tried then it looks at what the original URL was so it can send them to the right department's page or if it can't figure it out, sends them to a generic "that page is borked, go look for the right one" error page on Drupal.

Problem is, I'm a dumbass lol. I realized after writing it that the URLs that will be coming in are like:

http://www.company.com/Departments/Sale ... ducts.aspx

...so even though http://www.company.com points to the web instance with the PHP script, it won't run because it's not trying to load it. I realized that if I'm going to scrape all I should probably put the code on another domain so I need to grab any URL coming in on http://www.company.com and send it to ca.company.com/redirect/index.php passing the attempted URL so like ca.company.com/redirect/index.php?orig=http://www.company.com/Departments/Sales/NewProducts.aspx

How can I accomplish that with ISAPI Rewrite? I can get the redirect to work:

RewriteCond %{HTTP_HOST} ^www.company.com$
RewriteRule ^(.*)$ http://ca.company.com/redirect/index.php [R=302,L]

..but I don't know how to pass the attempted URL. Thanks!

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Redirecting with old URL?

30 Jan 2017, 09:13

Hello.

Actually what you need is to map all requests to PHP on the http://www.company.com website, that hosts your PHP redirection application. This simply can be done by creating a wildcard mapping in IIS settings without URL rewrite. Unfortunately, I could not quickly find an example of wildcard map for PHP engine in IIS, but it's rather straightforward.

Alternatively you can use ISAPI_Rewrite on http://www.company.com to rewrite all URLs to your redirect script, providing original URL as a query string (the whole of it) or as HTTP header X-Rewrite_URL: (will be available in PHP as X_REWRITE_URL in env or headers). Here is the rule example for .htaccess file:

RewriteEngine On
RewriteRule ^(.*)$ /redirect/index.php\?$1 [QSA]

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 18 guests