I have two URL rewrite rules. Individually they work perfectly, but when both are turned on, they are conflicting.
The first is in my root dir web.config, takes all requests to files in /seo/ and serves them by requests in the root of the website.
<rule name="RewriteToFile">
<match url="^(?!seo/)(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="seo/{R:1}" />
</rule>
The next one is in the web.config in a sub directory called /blog (it's a Wordpress blog).
<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>
Individually turned on, they work fine, but if both of them are on, the blog will only serve 403's...
Is there a way to enable both of these rules?
Related
Before anyone makes this a duplicate question please hear me out. I have researched several ways to do this that should work but I think because wordpress is running on this server it's causing conflict.
The setup: wordpress site running on a windows server. However, I have files in the webroot outside of the wp-content folder that users need to access. I need the extension removed on theses files.
When I use this:
<rewrite>
<rules>
<rule name="Redirect .php extension" stopProcessing="false">
<match url="^(.*).php$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{URL}" pattern="(.*).php$" ignoreCase="false" />
</conditions>
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
<rule name="hide .php extension" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}.php" />
</rule>
</rules>
</rewrite>
It takes the extesion off the urls but the pages outside of wordpress do not work. I think because of this which is in the web.config already:
<rule name="WordPress: http://hiddenwebsitewp.azurewebsites.net" 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>
Anyone have this problem before?
I have an existing IIS Server on which:
I have an existing open cart website inside a directory { example-url : abcd.com/open-cart-website/ }.
Now I have updated my main website with wordpress website. So now I have wordpress installed in abcd.com/ & opencart in abcd.com/open-cart-website/ .
I cant change opencart website url at all because it has existing PPC & SEO.
Index page of Opencart is accessible but none of the other page on open cart website is accesible, instead an error from wordpress is shown with error 404.
Need help!!!
I wrote down some rules in web.config of my wordpress website and now both are working.
Here are the rules, may be it helps some other developer.
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" negate="true" pattern="^/open-cart-website/*" ignoreCase="false" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
<rule name="Main Rule1" stopProcessing="true">
<match url="^([^?]*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" negate="false" pattern="^/open-cart-website/*$" ignoreCase="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
I'm trying to setup an IIS rewrite rule to add '.html' to URL's that don't have an extension, eg:
Original URL: www.domain.com/page
Rewrite to: www.domain.com/page.html
And I want to ignore any URL's that have an extension (eg. if they are images or other files)
Does anybody know the rule that I would need to set this up?
I worked this out myself by modifying a rule that I had on another website:
<rule name="rewrite directories to html" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" pattern="(.*?)\.[a-zA-Z]{1,4}$" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.html" />
</rule>
I am trying to setup a single page application with a Web API restful back-end. I used the "OWIN WebAPI SPA Template" to start my project. This template defaults the static file serving to the public/ folder within the solution's root directory. I want to support html5 urls, IE. localhost/madeUpPath which should hit the index.html page. In order to do this, I setup a rewrite rule in the Web.config file:
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="api/" ignoreCase="true" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
The issue I am having is that since the static files live in /public/ the {REQUEST_FILENAME} thinks the file is relative to / and the url localhost/main.css is rewritten to localhost/
I have tried changing the rule to this:
<add input="public/{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="public/{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
but that did not work. How can I achieve my desired result? Thank you.
Edit: I found something that seems to work, but isn't exactly what I was looking for.
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url="([a-zA-Z0-9-_.\/]+\.(css|js|less|json|jpeg|jpg|png|gif|svg|xml|html))$" />
<action type="Rewrite" url="/public/{R:0}" />
</rule>
<rule name="Second 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="/" />
</rule>
</rules>
</rewrite>
Firstly, this code doesn't because you're using OWIN server for static files:
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
Could you please to use next code:
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url="^((?!(api|\.)).)*$" />
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
Regular expression gives us ability to ignore api and any file paths.
We also use Owin to serve content out of a sub folder and the following works perfectly for us:
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{APPL_PHYSICAL_PATH}public{URL}" matchType="IsFile" ignoreCase="true" negate="true" />
<add input="{APPL_PHYSICAL_PATH}public{URL}" matchType="IsDirectory" ignoreCase="true" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
It's very similar to this comment, but I changed their {REQUEST_URI} variables to {URL} so that it will also ignore existing files even if they have query strings, which is necessary for cache busting resources, like site.css?ec99043d9af49f2bd7c2.
Edit: I also just found this Microsoft example which with some tweaking may also work for this scenario, but I haven't tested it myself:
<rewrite>
<rules>
<rule name="Angular Routes" 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="/MyApp/" />
<!--<action type="Rewrite" url="/" />-->
</rule>
</rules>
</rewrite>
I have a question about having two blogs at the same host simultaneously. Here is my scenario:
The first blog is hosted in the root directory http://mathosproject.com/, and the second is hosted in a sub directory, http://blog.mathosproject.com/, which is linked to http://mathosproject.com/blog/.
I have tried to manipulate the web.config file of the root, by making it excluding the directory blog as following:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress8" patternSyntax="Wildcard">
<match url="^(blog|sample-page)*" ignoreCase="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(blog|index)" negate="true" />
</conditions>
<action type="Rewrite" url="blog/index.php" />
</rule>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(blog|index)" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
This actually helped me to be able to view the second blog, in blog, but as I processed to the sample-page, I was redirected to the first blog.
My question is, is there a way I can configure the web.config, so that it excludes a folder entirely?
Thank you in advance,
Artem
I guess this is so late but have answer so posting it.
In subdirectory blog, edit the web.config and put <Clear/> just after <rules> element.
That will make your both the blogs working fine.