Setup WordPress Permalinks on ASP.NET MVC Site

I’ve got a NopCommerce site (ASP.NET MVC) and I’m trying to add a WordPress blog as a subfolder of the main site.

The installation of WordPress was fine, all config files have been created and the blog works fine if you browser through it.

Read More

However, I now want to setup pretty permalinks by using the name of the post.

Normally when you setup permalinks, it generates either a .htaccess file for Apache or a web.config for Windows IIS7 Url Rewrites.

When I try and save the permalink settings, it sits there trying to load and eventually times out.

I’m guessing that because ASP.NET MVC uses Routes, the WordPress site doesn’t know what to setup.

Can anyone offer me guidance on how I can get the permalinks setup? Do I need to setup a Route on my MVC site perhaps?

Related posts

Leave a Reply

2 comments

  1. In the end I copied a web.config file from one of my existing blogs that is on a standard C# website.

    Normally WordPress generates the web.config file itself. I can only assume that WordPress hasn’t been setup yet to handle installation on .NET MVC websites.

    Creating a web.config file, in the root on the WordPress blog files, containing the following code should get it working:

    <?xml version="1.0" encoding="UTF-8">
    <configuration>
        <system.webServer>
            <defaultDocument>
                <files>
                    <clear/>
                    <add value="index.php"/>
                </files>
            </defaultDocument>
            <rewrite>
                <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>
            </rewrite>
        </system.webServer>
    </configuration>
    
  2. If you install WordPress on IIS you will notice your friendly URLs do not work. This is because WordPress wants to use an apache add-on called “mod_rewrite.” The quick rundown of that this does is it will take your friendly browser URL and actually change them to index.php on the back end. One problem with this method is that IIS does not load apache mods. Here is an easy and free way around this:

  3. On your IIS Server download and install ISAPI_Rewrite Lite. This filter does the job of mod_rewrite for IIS. When downloading make sure to use the free Lite version. This Lite version does not limit the product very much and will be perfectly fine (and free) for our wordpress blog. Just install Rewrite Lite to the default locations for this tutorial.
  4. Next add the ISAPI filter to your IIS Site.
    You will find this setting by right clicking yourIIS site -> properties -> ISAPI filters tab -> Add … Name the filter whatever you wish and your path to your executable should be:
    C:Program FilesHeliconISAPI_Rewrite3ISAPI_Rewrite.dll
    Click OK on both windows to save your settings.
  5. Next navigate to C:Program FilesHeliconISAPI_Rewrite3

    Here we will edit httpd.conf (Note: This is the difference between the pay version and the Lite version. In the pay version you will need to edit the .htaccess file on your web folders root)

  6. Open the httpd.conf file in wordpad and paste in these lines:
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?p=$1 [NC,L]
  7. Save and exit this file.
  8. To complete your IIS changes, Go to start, run and run the command: iisreset /restart
  9. Now lets change your WordPress settings. Navigate to http://yourblog/wp-admin
  10. Navigate to the left side menu bar -> settings -> Permalinks
  11. Now you get to choose how you want your posts to look. I choose a custom setting and just: /%postname% This is how you see this blog working today.
  12. Click “Save Changes” and you should see your new friendly URLs!