web.config load website from specific folder - wordpress

I want to host multiple wordpress sites under the same domain, but different paths in azure web apps.
So on the server I would have a web.config under wwwroot and the wordpresssites under their own directory.
wwwroot - web.confing
| \ wp1
| \ wp2
Currently my web.config looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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>
and it works as long as all my files are in the wwwroot.
How should I rewrite it so it serves from wp1 when I enter domain.com/wp1 and serves wp2 when I go to domain.com/wp2?

The post "WordPress installation on Root Folder & Sub Folder on IIS Server, url conflict" on Wordpress support site may help you.
Also the SO question "Second Wordpress installation on IIS server" may be helpful.
They both show a configuration where one installation is on the root and one in subdirectory. But these should offer guidance on your setup.
You can find a good walkthrough also from here: http://www.erichstauffer.com/web-design/install-wordpress-root-folder-sub-folder-windows-iis-server-godaddy

I'd recommend leaving the default web.config in each Wordpress folder and create virtual directories in the Azure Portal for wp1 and wp2 - similar to the image below, but instead of blog2, you will have the root and 2 virtual directories /wp1 and /wp2. In the root, put whatever static html or redirects you require:

Related

web.config not working with WordPress permalinks in sub folder

I have WP installed on an IIS server in the root folder. This works with pretty permalinks.
There is also another wordpress install at /development which uses the following web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress1" 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>
<staticContent>
<clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00"/>
<remove fileExtension=".woff"/>
<remove fileExtension=".woff2"/>
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2"/>
</staticContent>
</system.webServer>
</configuration>
However, pretty permalinks are not working on this site in the subfolder
The home page works however of this sub folder and when plain permalinks are selected
Any ideas why?
The answer as pee2pee says, is to place that line in the code.
<remove name="YourRuleName"/>
To do this you must first look at the web.config file of the root and look for this line.
<rule name = "YourRuleName" patternSyntax = "Wildcard">
and then copy the line in the web.config file of your directory or subfolder, changing "YourRuleName" to the name you found in the web.config file of the root just above the first tag.
Then, your web.config file of the sub folder should look like
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<remove name="YourRuleName"/>
<rule name="YourSubFolderRuleName" 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>
I hope it is helpful, for me it has been.
Ensure the root folder (serving the primary site) and the subfolder (where the secondary or /shop resides) each have a unique web.config file.
In your subfolder’s web.config file you need to remove the rule that was set in the root folder. In our case, the WordPress rewrite rule set in the root folder was called “PrimarySite”, so in the subfolder’s web.config we have:
<remove name="PrimarySite"/>
And that’s all it took to get things working. Simple, eh?
As of WP 5.9 (but I am sure way back years and versions) there is no need to add web.config manually.
In case IIS rewrite module is installed (whichi is a prerequisite) when you modify Settings/Permalink, WP automatically emits web.config into the root of your site.
It even writes to the GUI a warning message, to revoke write access from web.config.
If IIS rewrite module is not installed, all of this above is not possible, neither manually, so WP will include the /index.php/ fragment in the path. If you overwrite this setting with a custom permalink setting, then the links will adopt (so will not contain the /index.php/ fragment, but because of lack of rewrite facility IIS will give 404.

IIS-7 wildcard redirect web.config with wordpress

Have a wordpress site running on IIS 7 shared server that is replacing an html site. I have only experience with apache so....
Need to modify the web.config file for the following
Add wildcard redirect to redirect all old site .htm pages to corresponding wordpress page. so /about.htm would got to /about and /contact-us.htm would go to /contact-us
Also need to add some specific redirects that will work within wordpress
For example:
http://sitename.com/articles redirects to http://sitename/news-and-events
Below is the default web.config file that was installed...and is working as far as general wordpress functionality.
I have tried some suggestions I found here that were related to removing .aspx but either they seem to have no effect or caused 500 error. Also as I am not sure if I am placing the rules in the right place/order within the file hierarchy.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress: http://sitename.com" 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>

Porting a Web.Config to ASPNET5

I upgrading my project to ASPNET5. I'm hitting a snag regarding upgrading my web.config file.
I tried using Microsoft.Framework.ConfigurationModel.Xml package to read a URL Rewrite configuration. The config looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="default.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
but of course I'm getting duplicate key issues when it tries to convert it to the object that aspnet5 uses.
Whats the best way to port your existing web.config to the new aspnet model? This is a small case I realize but in the real world these configs are really intense.
I've created an example project that I'm hoping to share with others when i get a few of these cases figured out.
the web.config file you posted only has url rewrite rules for iis. Do you really need to access those from your app? IIS will read those directly from the web.config but you shouldn't need that stuff in your app so you don't need to try to parse that file with the new classes in Microsoft.Framework.Configuration at all.
if your app needs some other settings then you might as well use a json.config file as shown in many examples for your own application settings.
you can still drop that web.config file into the application root and assuming your app is hosted in IIS it should still do its job and tell IIS to do some url rewriting. you should not rename it to config.xml as it appears you have done, since IIS won't notice the file unless it is named web.config
why would you need to access those url rewrite rules from application code at all since it is IIS and not application code that does the url rewriting?
I think the new paradigm is use json.config and/or environment variables in azure for application configuration
The only thing you might still use a web.config file for is IIS configuration but that is separate from application configuration and that is the only thing you would use web.config files for going forward and you should not need to access web.config file from application code at all.

Restrict IIS virtual directory to specific HTTP host header?

I have a website setup in IIS with 2 HTTP Headers (www.mysite.com and [blank]).
There is a virtual directory called 'blog' which points to a WordPress site - this is accessed via www.mysite.com/blog/
Any other requests (e.g. www.site1.com, www.site2.com, something.mysite.com) are handled by the same site (using the [blank] header) and rewrite rules to display the necessary information.
The problem is I don't want /blog/ to be available to anything other than www.mysite.com, as presently I can access it with any of the following:
www.site1.com/blog/
something.mysite.com/blog/
This is because we are also using BlogEngine (for user blogs) and if they set their blog directory to be 'blog' then it clashes with the WordPress one.
Ideally I'd like to be able to add a host header to the virtual directory, but can't find a way to do that, so looking for any other solutions (other than moving the WordPress blog).
Thanks in advance
You can prevent browsing to /blog on non-www.mysite.com sites using a UrlRewrite rule:
<rule name="RequestBlockingRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="/blog*" />
<add input="{HTTP_HOST}" pattern="www.mysite.com" negate="true" />
</conditions>
<action
type="CustomResponse" statusCode="403"
statusReason="Forbidden: Access is denied."
statusDescription="You do not have permission to view this directory or page." />
</rule>

WordPress 3.0.1 Install on MS IIS v6 Web Server

I have just installed WordPress 3.0.1 running on MS IIS 6 Windows Server that I developed from my Mac OS X platform.
Note that my WordPress setup is under the following directory structure:
c:\inetpub\wwwroot\MYSITE
The problem here is though, with the site up and running, it can't seem to find any of my pages like "About Us" even though I have set them up correctly within the permalinks side of things.
I am getting:
HTTP Error 404 - File or directory not found. Internet Information Services (IIS)
Is it something to do with permalinks/.htaccess file not working on MS II6?
.htaccess files are for Apache HTTPD. They don't work with IIS. For IIS you need to create a "Web.config" file and add the following lines to it.
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<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>
DOESN'T WORK IN IIS6:
As Kev points out, this code doesn't work in IIS6. From a little googling I understand that URL rewriting is not at all possible with IIS6. If anyone knows another way, please update here.
POSSIBLE ALTERNATIVE FOR IIS6?
Is it possible to use ISAPI_Rewrite or UrlRewriter.NET in this situation? Can someone clarify on this?

Resources