<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1822615684631785&amp;ev=PageView&amp;noscript=1"/>

How to serve WordPress pages and ASP.NET MVC pages from the same IIS folder

I have a problem.

I coded a bunch of landing pages as ASP.NET MVC Views as part of the GMass website, and now I want to convert those landing pages to WordPress so that they can be more easily managed, and so I can easily create more of them.

The landing pages are at URLs like:

https://www.gmass.co/gmail-mail-merge

https://www.gmass.co/email-outreach

but I also have MVC pages at the same root level like https://www.gmass.co/pricing that I do NOT want to convert to WordPress that should remain functional as .NET pages.

So I want to convert the existing MVC landing pages to WordPress and keep the URLs the same for SEO purposes.

Here is how I accomplished that.

Step 1: Copy WordPress files to root folder of IIS site

The root folder of my IIS website looks as you would expect:

The root GMass folder on my IIS web server

I installed WordPress at the same root level, which crowds the files and folders, but otherwise doesn’t do any harm. I’m assuming that PHP is already installed on your IIS server. If not, here’s how to install PHP on IIS.

The root GMass folder on my IIS web server, after I install WordPress

Note that I also have WordPress installed in the /blog folder, and the GMass blog is driven entirely by WordPress, but in the /blog folder, everything is served by WordPress, so there aren’t the complexities of the setup here, which involves serving some pages with .NET and some pages with WordPress.

So, I have two installations of WordPress connected to two different MySQL databasesone in the root GMass folder and one in the gmass.co/blog folder.

There is a way to have one installation drive TWO WordPress sites, but I didn’t want to bother with that.

Step 2: Create a new MySQL database just for the landing pages

Create the new database to store the landing pages in MySQL using MySQL Workbench.

Open up wp_config.php, and replace the sample information with the actual database credentials. I will call my new MySQL database “GMassLandingPages“. Of course, you could use an existing MySQL database, like the one for your WordPress blog that already has the WordPress table definitions, but I like to keep things clean and organized, so I’m creating a separate database just for my landing pages.

My wp-config.php file, which uses my new “GMassLandingPages” database.

Next, I have to go to https://www.gmass.co/wp-admin to complete the setup of my new WordPress installation. The setup will have me create my WordPress Administrator login, and it will set up the GMassLandingPages database that I just created. Meaning, it will create the necessary tables and other MySQL metadata needed for the database to function as my WordPress database.

Step 3: Create a WordPress page

Now, we’re ready to create a test page in WordPress that should be accessible at the URL https://www.gmass.co/landing-gmail-mail-merge

I copy the contents of my MVC landing page into my WordPress page.

Note that this URL is different from the original URL because I want to get it working first — then I’ll change it to the actual URL, without the word “landing” in it.

I set it up in WordPress, and navigate to the URL https://www.gmass.co/landing-gmail-mail-merge.

Navigating to the URL of the WordPress page doesn’t work, as I would expect

Nope, doesn’t work, but that’s what I would expect. How does IIS know whether PHP or .NET should serve this URL?

The MVC Router is looking for a matching controller to route the request to but doesn’t find one. I need to get PHP to process this request, not MVC.

I’ll do that by adding an IIS URL Rewrite Rule. If you don’t have the IIS Rewrite module installed yet, that’s your first step. I won’t explain how to do it here, but it’s pretty easy if you Google it. Hint: Use the Web Platform Installer.

Once the module is installed, there are two ways to manage your IIS URL Rewrite Rules: do it through the interface in IIS, or just edit the web.config file manually.

I prefer editing the web.config file manually because it’s faster for me.

Here’s what I need to add to web.config so that the https://www.gmass.co/landing-gmail-mail-merge page works:

Setting a URL Rewrite rule in web.config is necessary for the WordPress pages to be served.

In English, this URL Rewrite rule says that if the URL contains the string “landing”, route the request to index.php instead of MVC. The “rewrite” to index.php is at the core of how WordPress works on IIS. Meaning, if you have your entire blog running on WordPress on IIS in a separate /blog folder, you’ll see a similar entry in the web.config under the /blog folder.

Now, the setup works, but my landing pages look ugly. It doesn’t match the red background and text styles of my existing MVC page. This is where I hand-off the project to a WordPress expert who can appropriately style my landing pages to match the look of the .NET versions of the landing pages. A WordPress expert created a custom theme for my landing pages that matches the look and feel of the existing MVC landing pages.

Great, now my test landing page is working. I can also create as many “Pages” as I want in WordPress, and as long as they contain the word “landing” in the URL, they will work.

Now the WordPress landing page is working.

But remember, I want to migrate my landing pages to WordPress and keep the URLs the same, so I don’t lose any SEO juice.

I could make things easier on myself if I decided that changing the URLs is acceptible that all my WordPress pages will have URLs containing the word “landing”. Then I can use the one rule I added to web.config. But for now, I don’t want to do that.

First, I’m going to edit the URL in WordPress and remove the “landing” portion of the URL.

I’m removing the “landing-” portion from the Permalink in WordPress.

Now all I have to do is add an entry in web.config for this specific page, so that it’s served by WordPress and not .NET. I’m going to remove the first rule I put in that was based on the string “landing” and replace it with this rule, that will handle this one specific landing page.

Since I want to keep the URLs of the landing pages the same in the move from MVC to WordPress, I will create a separate rule for each landing page.

And voila! The final page, using the same URL, is now being served by WordPress and not ASP.NET.

And that’s it! This page is now being served from WordPress instead of .NET MVC.

If my landing page URLs don’t follow any specific pattern or have a string in common, then I’ll have to create a Rewrite rule for each landing page, but that’s a simple task, and the benefit of manaing my landing pages in WordPress far outweighs the inconvenience of having to add Rewrite rules to my web.config file.

Step 4: Celebrate!

Check it out! So now, my WordPress pages work and are served by WordPress:

www.gmass.co/gmail-mail-merge

and my MVC pages like my Pricing page are still served with MVC:

www.gmass.co/pricing

and both are in the same root level folder of my IIS installation.

Bonus: how do you know whether MVC or WordPress is serving a particular page?

Everything might be working, but you might want to be certain that WordPress is serving a page and not MVC. Of course, you could make a simple edit to the page in WordPress and then just reload it in the browser, but it’s easy to tell using Chrome’s Developer Tools. Just right click the page, choose Inspect, and then navigate to the Network tab, and look at the Response Headers.

The original landing page, served by ASP.NET MVC.

And here’s the new version of the page, served by WordPress:

The same landing page served by WordPress (PHP).

Notice the difference in the X-Powered-By response header. This headers tells you whether the page was served by PHP (meaning WordPress) or by MVC.

Email marketing, cold email, and mail merge inside Gmail


Send incredible emails & automations and avoid the spam folder — all in one powerful but easy-to-learn tool


TRY GMASS FOR FREE

Download Chrome extension - 30 second install!
No credit card required
Love what you're reading? Get the latest email strategy and tips & stay in touch.
   


15 Comments
  1. Awesome post I am obliged for sharing this. I’m a newcomer to Dot net developer but have used wordpress for long time. I needed exact information for my new project. It is an informative article, keep sharing.

  2. Very good read. Thank you for sharing. I am also a Developer. This is great and informative article. So thank you.

  3. Thanks for your tips, it’s helped me a lot. But I’m using this change to my Web.config file and I think it is more effective, as it should make IIS ignore all WordPress files and pages (/wp-), OR .php pages…

  4. Awesome post. I have it working exactly like this, however I want to achieve exact opposite.

    I need to server all static pages home, about, contact, blogs and case studies using wordpress as it is way easier for non technical colleagues to amend, while all the secure pages after a user is logged in (login, profile, edit profile, messages) etc, using asp.net.

    Is that possible?

    I have the following in global.asax

    and the following rules in web.config

    all the above rules work and serve blog, case-studies and contact using wordpress, however the home page is the last remaining problem, still being serve by asp.net

    link to dev site below.

  5. Hi Ajay, great article. Any chance you could share your URL Rewite config for hosting a WP blog in a sub-directory?

    I have added the WP site to a sub-directory “blog”. The landing page loads at /blog, however, none of the posts load. I believe that IIS is still trying to process them rather than letting WP do it.

    Many thanks.

  6. I managed to replace the homepage of an ASP.NET MVC site, however, when editing the page in the WP Admin, the publish process does not work. The latest version of WP calls wp-json when publishing which isn’t a file in the WP directory.

  7. Wow! This could be one particular of the most helpful blogs We’ve ever arrive across on this subject. Basically Wonderful. I’m also an expert in this topic so I can understand your effort.

  8. i could only wish that solar panels cost only several hundred dollars, i would love to fill my roof with solar panels”

  9. It was virtually any exhilaration discovering your website yesterday. I came here today searching new things. I was definitely not frustrated. Your ideas following fresh techniques with this thing happen to be useful additionally a good outstanding help individually. All of us value you leaving out time for you to create these products and also for uncovering your ideas.

  10. {Can I just|simply say what a relief|aid|reduction to find|to seek out|to search out someone|somebody who actually|truly|really knows|is aware of what theyre talking|speaking about on the internet. You definitely|undoubtedly|positively know how to|the way to|tips on how to|methods to|easy methods to|the right way to|how you can|find out how to|how one can|the best way to|learn how to bring|convey|deliver|carry an issue|a problem|a difficulty to light|mild|gentle and make it important. More|Extra people|individuals|folks need to|have to|must read|learn this and understand|perceive this side|aspect|facet of the story. I cant believe|consider|imagine youre not more|no more popular|well-liked|in style|fashionable|common|widespread|standard because you|since you definitely|undoubtedly|positively have the gift.

  11. Took me time to read all the comments, but I really enjoyed the article. It proved to be Pretty helpful to me and I am positive to all the commenters here It is always nice when you can not only be informed, but also entertained Im positive you had fun writing this post.

  12. The following time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my choice to read, however I actually thought youd have something interesting to say. All I hear is a bunch of whining about one thing that you may fix for those who werent too busy on the lookout for attention.

Leave a Reply to Jordan Cancel reply

Your email address will not be published. Required fields are marked *

Start your free trial of GMass now

Install in 30 seconds — no credit card or sign up form required

Try GMass for free Then check out the quickstart guide to send your first mail merge email in minutes!

GMass

Share This