IIS 7 URL Rewrite Module support in WordPress 2.8

I am pleased to let everyone know that WordPress development community has added a built-in support for IIS 7 URL Rewrite Module in the upcoming WordPress 2.8 release. Starting with version 2.8 the Permalink Settings page will allow you to easily configure “Pretty Permalinks” URL structure when WordPress is running on IIS 7 with URL Rewrite Module v1.1 installed.

Here is how the process of updating Permalinks structure will look like in WordPress 2.8 on IIS 7:

  1. Go to Settings –> Permalinks page and choose the permalink structure that you prefer:
    Permalink Settings page with Pretty Permalinks
  2. After clicking on “Save Changes” button the generated rewrite rule will be displayed with the instructions on how to update the web.config file manually:
    Permalink Settings Page with rewrite rule example
  3. Now you can copy the the given XML and put it into the web.config file inside of /<configuration>/<system.webServer>/<rewrite>/<rules> element and that’s it!
  4. Alternatively – instead of manually editing the web.config file you can have WordPress to update it automatically for you. To do that, temporarily grant WordPress write access to web.config file and click on “Save Changes” again. WordPress will add its rewrite rule into the proper location inside of the web.config file. Do not forget to revert the write permission on web.config file after the rule has been saved.

If you want to try this functionality, as well as all the other new features in the upcoming WordPress 2.8 release, you can download the latest nightly build. Also, pretty soon the 2.8 beta will be available.

Thanks to the WordPress development community for adding this functionality! Specifically, big thanks to peaceablewhale, Denis-de-Bernardy, hakre, sivel and ryan for directly working on the patch and contributing to it in many different ways: testing, code reviewing, cleaning up the code and checking it in.

4,840 views

ruslany on May 15th 2009 in PHP, URLRewrite, WordPress

PoorFairAverageGoodExcellent (2 votes, average: 5.00 out of 5)

29 Responses to “IIS 7 URL Rewrite Module support in WordPress 2.8”

  1. Gravatar Imagedeepure responded on 22 May 2009 at 10:14 am #

    Hi, I need to add this rules for wordpress,RewriteRule /tag/(.*) /index\.php\?tag=$1,but it’s used on helicontech’s software.I tried import in iis7 rewrite-module but it does’t work! Can you help me change the rule to iis7? Thanks a lot!

  2. Gravatar Imageruslany responded on 22 May 2009 at 6:05 pm #

    you will need to remove the slash at the beginning of the pattern. Also the substution url in your rule looks incorrect. Try this:

    <rule name=”somerule”>
    <match url=”tag/(.*)” />
    <action type=”Rewrite” url=”index.php?tag=$1″ />
    </rule>

  3. Gravatar ImageSayuri responded on 28 May 2009 at 2:21 pm #

    Hello, we hav install WordPress 2.8 beta2 on IIS 7 with URL Rewrite Module v1.1, but we have no Code under the “Save Changes” button. We have write the code from your screen in the web.config but also a 500 Mistake. Sry my eglish issent good.

  4. Gravatar Imageruslany responded on 29 May 2009 at 12:33 am #

    Sayuri, is IIS configured to run PHP via FastCGI? The WordPress will offer the pretty permalinks option only if PHP is running via FastCGI.

    Also, when WordPress shows the permalink options, do they contain “index.php”?

  5. Gravatar ImageAndrea responded on 29 May 2009 at 8:25 am #

    Hi-
    We are working on permalinks – and I have same issue as Sayuri. How do we check to see if PHP is running on FastCGI. I think it is but not sure how to confirm.

    Thanks you for posting this information about WP and IIS7!

  6. Gravatar Imageruslany responded on 29 May 2009 at 9:05 am #

    Andrea,

    There are three conditions that need to be true in order for WordPress 2.8 to offer pretty permalinks on IIS7:

    1. PHP is running via FastCGI
    2. PHP version 5 is used
    3. URL Rewrite Module 1.1 is installed and enabled.

    If any of those is not true then WordPress will work as in previous versions and will offer “Almost Pretty Permalinks” option.

    To check if FastCGI is used, call phpinfo() function and check the “Server API”. It should say “CGI/FastCGI”. Alternatively, call php_sapi_name() function. It should return ‘cgi-fcgi’.

    Please let me know if you see all three conditions to be true and permalinks still do not work. I will investigate further.

  7. Gravatar ImageAndrea responded on 29 May 2009 at 11:36 am #

    Thanks for the extra info – we manually edited the cgi.config file and made it match what shows in your step #2 above.

    it’s working now. Thank you.

  8. Gravatar Imageruslany responded on 29 May 2009 at 3:23 pm #

    Andrea, did WordPress show you the rewrite rule with the instructions text as shown in screenshot for step #2?

  9. Gravatar ImageMicrosoft Contributing to PHP Open Source Projects – Weird ? : Misfit Geek responded on 02 Jun 2009 at 7:13 am #

  10. Gravatar ImageCelso responded on 18 Jun 2009 at 9:00 pm #

    I am getting a fraking error on every page, every update of every field on the site since I upgraded to 2.8 iis. It is making me consider downgrading wordpress. I would appreciate any light on this issue:

    PHP Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(C:\SITES\HypeScience.com\www/C:\SITES\HypeScience.com\www/wp-content/plugins/all-in-one-seo-pack/all_in_one_seo_pack-en_US.mo) is not within the allowed path(s): (C:\SITES) in C:\SITES\HypeScience.com\www\wp-includes\l10n.php on line 324

  11. Gravatar Imageruslany responded on 18 Jun 2009 at 11:15 pm #

    Celso, thanks for reporting this. Looks like this is a bug in the plugin. It incorreclty passes an argument to a function load_plugin_textdomain, which causes the open_basedir warning.

    You can work around it by changing the init function in all_in_one_seo_pack.php file to look like this:

    function init() {
    if (function_exists('load_plugin_textdomain'))
    load_plugin_textdomain('all_in_one_seo_pack', false, 'all-in-one-seo-pack');
    }

    Note that after you change this you may run into another bug that only shows up with open_basedir enabled – http://core.trac.wordpress.org/ticket/10132. That one will be fixed in 2.8.1.

  12. Gravatar ImageCelso responded on 19 Jun 2009 at 12:24 pm #

    Thanks man. I rolled back the plugin and things got better. But i am getting the open_basedir enabled. Will wait until the next until 281.

  13. Gravatar Imageruslany responded on 19 Jun 2009 at 1:15 pm #

    The all-in-one-seo-pack plugin author has been informed of this bug and will look into fixing it in next plugin update.

  14. Gravatar ImagePhilip M. Hofer (Frumph) responded on 14 Jul 2009 at 10:35 pm #

    Unfortunately the 2.8.1 release of wordpress only allows a single rule to be manipulated into the web.config and not multiple rules as such is needed for WPMU and future rules as needed.

    Hopefully an update that loops through listed rulesets will fix this in a future patch.

    - Phil

  15. Gravatar Imageruslany responded on 20 Jul 2009 at 11:04 am #

    The patch for WPMU 2.8 has been provided and it should be fixed in future releases of WPMU.

  16. Gravatar ImageVijay Bandari responded on 06 Aug 2009 at 9:40 am #

    hi…
    recently i setup wordpress 2.8 with on IIS 7 with fastCGI and Rewrite Module is installed.
    I am not seeing any code section as in screeshot #2, i want to have a url with out index.php so i setup custom structure to “/%year%/%monthnum%/%day%/%postname%/” but the links are not working.

    Can you please guide me in fixing this issue.

  17. Gravatar Imageruslany responded on 06 Aug 2009 at 9:54 am #

    Vijay, please check the conditions described in this comment and let me know what you find.

  18. Gravatar ImageDavid Potter responded on 13 Nov 2009 at 6:56 pm #

    Great module – thanks so much! 2 questions.

    1. Your rewrite rule is different than the one created by WordPress. Is there a difference in performance or behavior between the two?

    2. I’d like to have anyone who navigates using index.php receive a permanent redirect to the URL without the index.php. Is there a way to do that?

    Here are my versions:
    - Windows Server 2008 R2
    - URL Rewrite Module v2.0 RC
    - PHP 5.3.0
    - WordPress 2.8.5

    Thanks,
    David

  19. Gravatar Imageruslany responded on 15 Nov 2009 at 3:33 pm #

    @David:

    1. No, there is no difference in performance. URL rewrite module caches the rewrite rules logic, so it does not matter if wildcard or regex is used for the rule. The wordpress rule uses wildcard patterns, because it is simpler.

    2. It is relatively easy to do. Just create a redirect rule that has pattern “^index\.php” and then redirects to “/”. Place this rule before the rewrite rule generated by the wordpress.

  20. Gravatar ImageSunil Jain responded on 18 Jan 2010 at 10:16 am #

    Hello Ruslany , i am in deep trouble . pls help me
    I am getting this error on my blog’s homepage header and also i am unable to login to my admin panel

    Below are the errors i am getting in my blog
    1. On the Header :
    “Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(/customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-content/plugins/index.php/languages/index-en_US.mo) is not within the allowed path(s): (/customers/gupshupblog.com/gupshupblog.com:/tmp:/var/www/diagnostics:/usr/share/php) in /customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-includes/l10n.php on line 329″

    And this error i recive when i try to login to my admin panel
    Warning: is_readable() [function.is-readable]: open_basedir restriction in effect. File(/customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-content/plugins/index.php/languages/index-en_US.mo) is not within the allowed path(s): (/customers/gupshupblog.com/gupshupblog.com:/tmp:/var/www/diagnostics:/usr/share/php) in /customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-includes/l10n.php on line 329

    Warning: Cannot modify header information – headers already sent by (output started at /customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-includes/l10n.php:329) in /customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-includes/functions.php on line 790

    Warning: Cannot modify header information – headers already sent by (output started at /customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-includes/l10n.php:329) in /customers/gupshupblog.com/gupshupblog.com/httpd.www/wp-includes/functions.php on line 791

    So pls help me out in resolving this ??? :( :( :(

  21. Gravatar Imageruslany responded on 18 Jan 2010 at 10:26 am #

    Sunil, can you open the php.ini file used by your PHP installation and check what is the value specified for the open_basedir directive? I suspect that it may have been specified incorrectly. The paths should be separated by “;”, but in your case it looks like they are separated by “:”.

  22. Gravatar ImageJohn responded on 02 Feb 2010 at 10:16 pm #

    I am getting a 404 error on all my posts after implementing this change. Do you know why that might be? I meet all the requirements

    php 5.2.9
    iis 7
    url rewrite 2.0

    I set the proper permissions and let WP modify my web.config the rule got created ok and everything works on the site EXCEPT for posts.

  23. Gravatar Imagea43 responded on 08 Feb 2010 at 12:58 pm #

    Hi Ruslan,

    I am trying to redirect all of my blogengine like urls to my wordpress blog but struggling to accomplish this task. Please help!

    blogengine url format: http://www.mydomain.com/post/2010/02/07/this-is-the-post-title.aspx

    wordpress url: http://www.mydomain.com/2010/02/07/this-is-the-post-title/

    I’ve added a new rule along with the wordpress rule for some reason i am getting the old 404 error when I try the blogengine url format.

    The site is hosted on ISS7 and PHP5 (godaddy windows shared hosting)

    please have a look at my web.config and let me know if i am doing anything wrong:

    <configuration>
    <system.webServer>
    <rewrite>

    <rules>
    <rule name="Redirect(301) all legacy BlogEngine posts">
    <match url="(/20[0-9][0-9]/\d{2}/\d{2}/)(.*).aspx" />
    <action type="Rewrite" url="{R:0}{R:1}/" />
    </rule>

    <rule name="wordpress" patternSyntax="Wildcard">
    <match url="*" />
    <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php" />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>

    Please Note: the wordpress rewrite works fine.

  24. Gravatar Imageruslany responded on 09 Feb 2010 at 5:29 pm #

    @a43: This is most probably because the pattern for the redirect rule is incorrect. Try this rule instead:

    <rules>
    <rule name="Redirect(301) all legacy BlogEngine posts">
    <match url="^post/(20[0-9][0-9]/\d{2}/\d{2}/)(.*).aspx" />
    <action type="Rewrite" url="{R:1}{R:2}/" />
    </rule>

  25. Gravatar Imagea43 responded on 10 Feb 2010 at 10:28 am #

    Ruslan, thanks for the reply.

    I did try your rule unfortunately it didn’t work, still getting the 404 error.

    after loads of googling and “trail and error” managed to get the following rule to work on my environment:

    <rule name="Redirect(301) all legacy BlogEngine posts" stopProcessing="true">
    <match url=".aspx" />
    <conditions>
    <add input="{HTTP_URL}" negate="false" pattern="(/20[0-9][0-9]/\d{2}/\d{2}/)(.*)\.aspx" />
    </conditions>
    <action type="Redirect" url="{C:1}{C:2}/" redirectType="Permanent" />
    </rule>

    can you see any differences? I still can’t understand why your suggested rule didn’t work.

  26. Gravatar Imageruslany responded on 10 Feb 2010 at 12:42 pm #

    My rule did not work because its pattern starts with ^post. It looks like your URLs do not actually start with /post, so if you modify the rule pattern to be “(20[0-9][0-9]/\d{2}/\d{2}/)(.*).aspx$” then it should work. Note that it is important to not have the “/” at the beginning of the pattern.

  27. Gravatar Imagea43 responded on 11 Feb 2010 at 12:34 pm #

    Thanks Ruslan

  28. Gravatar ImageShir responded on 28 Feb 2010 at 7:57 am #

    Hi,

    I have tried to apply it on my site, which runs on IIS 7, unfortunately it seems to be working only when the page slug is written in english.
    When I try to click on a page where the slug is in hebrew letters such as פרופיל (Profile) it goes to my custom 404 page.

    Is there any solution for this? Thank you.

  29. Gravatar Imageruslany responded on 02 Mar 2010 at 11:46 am #

    @Shir: there is a known issue in IIS 7 FastCGI module in how it handles the REQUEST_URI server variable for non-ascii characters. IIS team is planning to provide an update for it soon.

    Meanwhile you can use this workaround:

    In the wp-config.php file add this code:

    if (isset($_SERVER['UNENCODED_URL']))
    $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];

Trackback URI | Comments RSS

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

XML Markup: If You want to add XML code to the comment please XML encode it first, otherwise the code will not show up.

Recently Published Articles