I want to deploy my site to Windows hosting from linux. On Linux server everything working as expected. but few things are not working on windows server.
Please let me know what changes i need to do in web.config
My file system is:
-src
-webroot
--css
--about.html
--index.php
--contact.php
Now how i can access about.html directly http://www.example.com/about.html and similarly for other php files too.
these are rule i am using for now:
<rewrite>
<rules>
<rule name="Exclude direct access to webroot/*"
stopProcessing="true">
<match url="^webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)"
stopProcessing="true">
<match url="^(assets|font|fonts|img|images|css|files|js|favicon.ico)(.*)$" />
<action type="Rewrite" url="webroot/{R:1}{R:2}"
appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php"
stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
Related
I have a project in asp net core 2.0.
I Have stablished the next Rule in the web.config:
<rewrite>
<rules>
<rule name="wwwroot" >
<match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
<action type="Rewrite" url="wwwroot/{R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
When i acces to the url: www.foobar.com/lib/chart.js/dist/Chart.js for some reason the iis try to finde Chart.js in the path: wwwroot/lib/chart.js ignoring the last part of the url (/dist/Chart.js) when im expecting to take wwwroot/lib/chart.js/dist/Chart.js
Try to modify your regexp like this: ([\S]+[.](js|css|png|gif|jpg|jpeg))$ it should consider file extension if they at the end of your url
EDIT
To your rule you should exclude urls starting from wwwroot
<rule name="wwwroot" >
<match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" negate="true" pattern="^/wwwroot" ignoreCase="true" />
</conditions>
<action type="Redirect" url="wwwroot/{R:1}" logRewrittenUrl="true" />
</rule>
I am using this answer https://stackoverflow.com/a/13861795/848513 which works great for static files, which no longer exist on my site, to forwards to new file locations.
But I also have some dynamic URL's that need to be forwarded to new locations, and the following code doesn't seem to work:
Works:
<rule name="SpecificRedirect50" stopProcessing="true">
<match url="aboutus.php" /> <!-- static URL -->
<action type="Redirect" url="/about-us" redirectType="Permanent" />
</rule>
Does not work:
<rule name="SpecificRedirect1" stopProcessing="true">
<match url="topic.php?id=39" /> <!-- dynamic URL-->
<action type="Redirect" url="/folder/?id=520" redirectType="Permanent" />
</rule>
The error i get when trying to go to www.site.com/topic.php?id=39 is a 404 Not Found error - ie, it isn't being filtered by the rewrite script.
What should the format be?
Thanks
OK, found answer - this format works:
<rule name="SpecificRedirect1111" stopProcessing="true">
<match url="^topic\.php$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^id=39$" />
</conditions>
<action type="Redirect" url="/folder/?id=520" appendQueryString="false" redirectType="Permanent" />
</rule>
VS2010 IIS Express 8.0, trying to test rewrite rules in my development machine. I am adding this section to my web.config. Everything works until I add the 'rule' part inside the 'outboundRules' section, in which case I get the 500.52 error. I've tried all combinations or installing / uninstalling IIS, Windows Process Activation and all that, but nothing. Any ideas?
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<rewrite>
<rules>
<rule name="Rewrite to RewriteTest.aspx">
<match url="^RewriteTest/([0-9]+)/(g[_0-9a-z-]+)" />
<action type="Rewrite" url="RewriteTest.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
<outboundRules>
<rule name="Rewrite to clean URL" preCondition="IsHTML">
<match filterByTags="A" pattern="^/RewriteTest\.aspx\?id=([0-9]+)(?:&|&)title=([_0-9a-z-]+)$" />
<action type="Rewrite" value="/RewriteTest/{R:1}/{R:2}" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
I posted a question up yesterday basically I have a single plan with winhost and I want to be able to have multiple domains (that are all pointed at my root) go to different subfolders and in these sub-folders I host different MVC apps. A very helpful chap took me most of the way but (and I know its lame how difficult im finding this) but I really cannot work out how to do the final peice...
The IIS config...
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect if producerpte" stopProcessing="true">
<match url="^producerpte/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder">
<match url="^.*$" />
<action type="Rewrite" url="producerpte/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
works brilliantly. When I now go to http://www.producerpte.co.uk I can see my site in the subfolder but the url looks like its on the root. However I also want to try and host my girlfriends site so I have tried multiple combinations but I just cannot seem to add rules that will work for both sites...I know I need to add two more rules like this...
<configuration>
<system.webServer>
<rewrite>
<rules><!--first site-->
<rule name="Redirect if producerpte" stopProcessing="true">
<match url="^producerpte/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder producerpte">
<match url="^.*$" />
<action type="Rewrite" url="producerpte/{R:0}" />
</rule>
<!--second site-->
<rule name="Redirect if samyoga" stopProcessing="true">
<match url="^samyoga/(.*)$" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="Rewrite to sub folder samyoga">
<match url="^.*$" />
<action type="Rewrite" url="samyoga/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Whatever it is about the last rule I just cant get it to route. If I use it then when I go to Samyoga.co.uk I end up at Samyoga.co.uk/producerpte ?????
I tried matching the wildcard in the second rule (for each site) it just doesnt work at all then.....
A friend is having me figure out a way to modrewrite on his windows server. He is running IIS 6 and Isapi is about the only thing I can find. I am not familiar with it and have read some of the documentation, but can't quite wrap my head around it. He is wanting to rewrite these URLS to make them clean
www.domain.com/cat.php?CTGID=####
and
www.domain.com/pp.php?ID=##
How would I go about rewriting these two URLS to make them Clean in ISAPI. I have installed it on the Windows Server and do I put these rules in IISF.ini in his website folder or put these codes in the master IISF file? Any Help would be greatly appreciated!
Rewrite rules go in a web.config file or in the ApplicationHost.config.
As described in http://learn.iis.net/page.aspx/465/url-rewrite-module-configuration-reference/
Examples
<rewrite>
<rules>
<rule name="Force WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="Redirect from blog">
<match url="^blog/([_0-9a-z-]+)/([0-9]+)" />
<action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found" />
</rule>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
For IIS, if the ISAPI_Rewrite module is installed, $_SERVER["IIS_UrlRewriteModule"] is set and contains the version number of the module. So you can check for the existence of this server variable.