Jump to content
Sign in to follow this  
tubc2015

Web.config rewrite problems

Recommended Posts

Hi everyone, I'm trying to rewrite a URL (hide file extensions e.g .php, .html) using the rule 2 in my code, but its function has been overwritten by the rule 1. Because when I browse www.mysite.com/login.php it works which was supposed to be www.mysite.com/login, problem of rule 2. On the other hand, when I browse www.mysite.com/login it redirects to www.mysite.com/capture.php instead of www.mysite.com/login.php(actually login) its function is from the rule 1 and not from rule 2. The function of rule 1 is to rewrite a permalink: www.mysite.com/username and the rule 2 is to hide file extensions.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="rule 1" stopProcessing="true">
          <match url="^([^/]*)$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="/capture.php?user={R:1}" />
        </rule>
        <rule name="rule 2" stopProcessing="true">
          <match url="/login.php$" />
          <action type="Rewrite" url="/login" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Share this post


Link to post
Share on other sites

With rule 1 you are saying that if the URL does not match an existing directory or file, then redirect and stop processing any other rules. So it's never going to pass to rule 2 if the URL does not match an existing resource on the server. Rule 1 should probably be after rule 2.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...