3

I have a PHP website,

e.g. http://www.test.com/rewrite-test/s/z2SZhBL

This was previously on Apache which had a rewrite rule to trap the "z2SZhBL" using the $_GET['id'].

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /index.php?id=$1 [L]

I need to move this website onto IIS and I need to get the URL rewrite rule working. I have tried these examples.

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

So in the folder "rewrite-test" I have an index.php which is echoing out the $_GET variables and there are no get variables coming back they are all empty.

I can get the variables using this workaround.

$params = explode( "/", $_SERVER['HTTP_X_ORIGINAL_URL'] );
print_r($params);

Is this best solution?

davejal
  • 6,009
  • 10
  • 39
  • 82
davesherlock
  • 185
  • 1
  • 1
  • 9
  • your just asking an opinion? – davejal Nov 05 '15 at 15:24
  • 1
    Well I am wondering if this is the correct way to retrieve the variables after they are rewritten, it feel like what I have done might be a hack/workaround should the variable not be obtainable via the $_GET, perhaps what I have done is correct. – davesherlock Nov 05 '15 at 15:57
  • Just import your .htaccess file to your URL Rewriter. There is a small link to this wizard. All the same rules and techniques can be used. IIS will capture and rewrite it to the `index.php?id=$1` so you can continue to use `$_GET`. – Twisty Nov 05 '15 at 17:02
  • http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules – Twisty Nov 05 '15 at 17:03

1 Answers1

0

IIS Manager has a good Import Rules tool. See full walk through here: http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules

  1. Open URL Rewrite
  2. In Actions Pane, click Import Rules
  3. Browse to your .htaccess file (Or Copy/Paste them in)
  4. Review the Converted Rules
  5. Rename the rule as desired
  6. Click Apply Link to save the converted rules
Twisty
  • 30,304
  • 2
  • 26
  • 45
  • My question was more about how do you get the variables once you have the rule set up, at the moment I am using $params = explode( "/", $_SERVER['HTTP_X_ORIGINAL_URL'] ); – davesherlock Nov 05 '15 at 17:24
  • If the rule is working properly, you would use `$_GET['id']` as you had before. Both will work, just seems like a lot of work to explode the URL. Plus you then have no index on the data you get. – Twisty Nov 05 '15 at 17:26