We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

URL Rewrite not working - Displays 404RSS

16 replies

Last post Jun 11, 2013 04:17 AM by daninthetoon

  • URL Rewrite not working - Displays 404

    Mar 15, 2009 11:54 PM|yole79|LINK

    Hi,

    I have been playing around with the URL Rewrite module in IIS 7 and configured it on my local machine where it is working fine within the hosted application. I have now deployed the website to a test server where it is hosted as a web site only and now im getting an ASP 404 error page, Server Error in '/Reports' Application (which of course does not exist). I have no tried adding an application under the server's Default Web Site and pointed it to the same physical files as the deployed version and the URL Rewrite is working. Is there a trick to get it going under a web site?

    My Rewrite configuration:

    <rewrite>

    <rewriteMaps>

    <rewriteMap name="Reports"/>

    </rewriteMaps>

    <rules>

    <rule name="Reports">

    <match url="^reports/((.+)/)?(.+).aspx"/>

    <action type="Rewrite" url="Report.aspx?report={R:3}&amp;group={R:2}" appendQueryString="false"/>

    </rule> </rules>

    </rewrite>

    I have tried turning on tracing as per http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/ in an attempt to work out this problem, however the logs are not appearing.

    Any help will be greatly appreciated.

    Thanks,
    Dan

    URL Rewrite URL Rewrite Module RewriteModule rewrite redirect 404 pattern rewrite <rewrite> iis rewirte urlrewite subdomain

  • Re: URL Rewrite not working - Displays 404

    Mar 16, 2009 10:06 AM|jeff@zina.com|LINK

    Post the full error and look at the IIS logs to see what it is actually redirecting to, if anything.

    Jeff

    Have you Binged a solution before posting?
  • Re: URL Rewrite not working - Displays 404

    Mar 16, 2009 06:41 PM|yole79|LINK

    Hi Jeff,

    I have successfully enabled the tracing for the rewrite module, however neither the IIS logs or trace file have any information relating to the request when it is made.

    The exception is:

    Server Error in '/Reports' Application.

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /Reports/Person/EmployeeReport.aspx

    Thanks,

    Dan

  • Re: URL Rewrite not working - Displays 404

    Mar 17, 2009 11:43 AM|Andreas Broicher|LINK

    I am facing similar stuff with my Server:

    Server 2008 / IIS7 / URL Rewriter
    PHP / mySQL and as application Magento (Shopsystem)

    Everything is running fine when I am on the server console using the full qualified name for that application for example http://blahblahblah.domainName.com , but when I try the same from outside, NOT everything works as desired....because:

    404 errors should be redirected to the index.php in the root, but this works only as described when I am working on a console on the server.

    My Guess is that this has to do with the rights, as I have diffrent rights when I am directly on the console of the server, but I am just guessing.. any Ideas around?

    PARTLY SOLVED:
    I went into the IIS7 and opened the 404 Error handlers and hardcoded the path to the index.php in the root of my web. This made the trick, even tho i still dont know, why it worked on the console without this change.

    The Magento is now up and running fine with all features and pages working.
    In the mean time I have also understood that the Magento rewrite rules are just there to prevent access to some directories, because they have read write permissions for the IUSR_xxxxx

    Best wishes

    Tango

    IIS7 RewriteModule magento rewrite <rewrite> rewriterule

  • Re: URL Rewrite not working - Displays 404

    Mar 17, 2009 01:14 PM|ruslany|LINK

    Dan, it looks like the rule pattern never matches the requested URL which causes 404. Where is web.config file with rewrite rule located relative to the web site root? Also what is the actual URL you request, including the domain name?

  • Re: URL Rewrite not working - Displays 404

    Mar 17, 2009 01:19 PM|ruslany|LINK

    Andreas, this may be caused by IIS custom errors configuration. Refer to the post "Enable Custom Errors in WordPress" to see how this is solved for WordPress. May be in case of your application the solution can be similar.

  • Re: URL Rewrite not working - Displays 404

    Mar 17, 2009 05:35 PM|yole79|LINK

    Hi Ruslany,

    The rewrite rules are in the web config at the root of the web site, say c:\inetpub\mywebsite. The request goes to http://mywebsite/Reports/Person/EmployeeReport.aspx which should then map to http://mywebsite/report.aspx?report=EmployeeReport?group=Person. Just to clarify from my initial post, if i add a an application in IIS 7 under the Default Web Site pointing to the same physical files and make the request http://myserver/mytestsite/Reports/Person/EmployeeReport.aspx all works fine. Also if i point http://mywebsite to an empty folder then add the website as an application under that, the request http://mywebsite/mytestsite/Reports/Person/EmployeeReport.aspx works as expected. Keep in mind that rewrite configuration is now under mytestsite.

    Now i have tested pointing the Default Web Site of the server to mywebsite and the rewrite fails again. So it seems that its not working when being used under a Website rather than an Application. Is there any other configurations that have to be made in these cases?

    Thanks again,

    Dan

  • Re: URL Rewrite not working - Displays 404

    Mar 17, 2009 06:27 PM|ruslany|LINK

    From your description everthing looks correct. Having Failed Request trace log would really help figuring this out. Can you enable Failed request tracing for mywebsite, make a request to http://mywebsite/Reports/Person/EmployeeReport.aspx, then go to C:\inetpub\logs\FailedReqLogFiles\W3SVCN, where N is the ID of mywebsite and see if there are any log files there. In the log files look for events that start with URL_REWRITE.

  • Re: URL Rewrite not working - Displays 404

    Mar 17, 2009 08:13 PM|yole79|LINK

    I have enabled the trace to log RequestNotifications and Rewrite. Making a request to a physical page causes a trace to be logged, however making the request to the rewrite url fails to log anything. Same deal for the IIS log. Even if i enable tracing of every feature, still nothing gets logged at all when i make that request. It simply shows the exception page as in my previous post.

    Any other thoughts?

    Cheers

  • Re: URL Rewrite not working - Displays 404

    Mar 22, 2009 06:04 PM|yole79|LINK

    Anyone?

  • Re: URL Rewrite not working - Displays 404

    Mar 22, 2009 06:18 PM|DanielVL|LINK

    Hello,

    To be honest with you, if you enabled all the trace areas and you don't get any log at all, you may have missed some step for setting up Failed Request Tracing. Please send me your applicationHost.config file and the web.config file for your application as private message. I can take a deeper look.

    Thanks.

    FREB frt

    Daniel Vasquez Lopez
    IIS Team
  • Re: URL Rewrite not working - Displays 404

    Feb 02, 2011 10:20 AM|seanlmcgill76|LINK

    I'm having the same issue - I just get a 404 error, no failed request logs are being produced even though I have it enabled for all requests 200-404 for testing. I do however get see the request in the normal IIS log under C:\inetpub\logs\LogFiles. Studio 2010 tells me that under the node is an invalid child. The re-write module is installed properly, when I tried to install it just to check I got "Repair" or "Uninstall" options. Any ideas? Thanks, Sean Here's my web.config system.webServer section:

    <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" /> <httpRedirect enabled="false" destination="" /> <rewrite> <rewriteMaps> <rewriteMap name="/default.aspx" /> </rewriteMaps> <rules> <rule name="Rewrite rule1 for /default.aspx"> <match url=".*" /> <conditions> <add input="{/default.aspx:{REQUEST_URI}}" pattern="(.+)" /> </conditions> <action type="Rewrite" url="/Account/LogOn" appendQueryString="false" logRewrittenUrl="true" /> </rule> </rules> </rewrite> <tracing> <traceFailedRequests> <remove path="*" /> <add path="*"> <traceAreas> <add provider="ASP" verbosity="Verbose" /> <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" /> <add provider="ISAPI Extension" verbosity="Verbose" /> <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" /> </traceAreas> <failureDefinitions timeTaken="00:00:00" statusCodes="200-404" /> </add> </traceFailedRequests> </tracing> </system.webServer>

    rewrite 404 error mvc url tracing

  • Re: URL Rewrite not working - Displays 404

    Feb 02, 2011 11:08 AM|HCamper|LINK

    Hello,

    Could I suggest that you change the error code groups to be 200,300,400,500

    instead.

    You maybe not seeing 500 errors which might be your problem area.

    Post issues & questions to this thread.

    Maritn :)

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: URL Rewrite not working - Displays 404

    Sep 11, 2012 04:44 PM|aruizna|LINK

    Hi, I´m having the same problem. I have a MVC WebSite, where I need a Reverse Proxy. I already installed the ARR and the URL Rewrite (2.0) Module, enabled the Proxy and seted the inbound rewrite rule. When I try navigate the url that match with this rule return 404 Code. Just to be sure, I did the simple example that is explain in http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing It worked, so I repeated this rules in my website and didn't work What setting I´m loosing in my website? Any clue? Rewrite element in system.web in both web.config: Thanks, aruizna
  • Re: URL Rewrite not working - Displays 404

    Sep 11, 2012 05:04 PM|aruizna|LINK

    Hi,
    I´m having  the same problem.
    I have a MVC WebSite, where I need a Reverse Proxy. I already installed the ARR and the URL Rewrite (2.0) Module, enabled the Proxy and seted the inbound  rewrite rule. When I navigate the url that match with this rule return 404 Code.
    Just to be sure I installed the URL Writer and the ARR correctly, I did the simple example that is explain in http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
    It worked fine, so I created the same rule in my website and didn't work!

    What setting I´m loosing in my website?
    Any clue?

    The rewrite element in both web.config:

    <rewrite>
              <outboundRules>
                  <preConditions>
                      <preCondition name="ResponseIsHtml1">
                          <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                      </preCondition>
                  </preConditions>
              </outboundRules>
              <rules>
                  <rule name="ReverseProxyInboundRule4" stopProcessing="true">
                      <match url="^pictures/(.*)" />
                      <action type="Rewrite" url="http://localhost:8081/{R:1}" />
                  </rule>
              </rules>
          </rewrite>

    Thanks

    aruizna

  • Re: URL Rewrite not working - Displays 404

    Jan 20, 2013 06:54 AM|frankvaneykelen|LINK

    What worked for me was going to the Project's Properties, select the Web tab, and changing "Use Visual Studio Development Server" to "Use local IIS Web server", and accepting the default sub-settings of (in my case) "Use IIS Express" and Project Url "http://localhost:52246/".

    Now my rewrite rule in web.config is working properly, instead of ending up as a 404.

  • Re: URL Rewrite not working - Displays 404

    Jun 11, 2013 04:17 AM|daninthetoon|LINK

    Hi, stubled across this old post when I was trying to solve the same issue.

    SOLVED!

    Using Rewrite URL feature in IIS Services Manager I created a friendly URL rule, this worked ok and when I looked at the rule in the web.config file (www root) it showed 1 rule to redirect and 1 rule to rewrite, so I edited this to suite 1 match.  Then I just duplicated this code editing the product ID for each.... example below

                    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
                        <match url="^product\.php$" />
                        <conditions>
                            <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                            <add input="{QUERY_STRING}" pattern="^id_product=\b35\b" />
                        </conditions>
                        <action type="Redirect" url="990mm-bohemia-cast-iron-electric-radiator" appendQueryString="false" />
                    </rule>

    SO THE FIRST RULE LOOKS FOR STRING "product.php" IN URL AND LOOKS FOR "id_product=35" THEN REDIRECTS TO "990mm-bohemia-cast-iron-electric-radiator" WHICH CURRENTLY DOES NOT EXISTS...... THEN......


                    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                        <match url="^\b990mm-bohemia-cast-iron-electric-radiator\b" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="product.php?id_product=35" />
                    </rule>

    THIS RULE REWRITES THE "product.php?id_product=35" BIT TO "990mm-bohemia-cast-iron-electric-radiator" CREATING THE NEW LOCATION FOR THE REDIRECT, SIMPLES!