skip to Main Content

In server we are using Internet Information Services (IIS) with PHP, PHP Manager. I want to hide "dava" parameter, not only for /kovusturma-sartlari/onodeme/ page, in whole website "dava" key should hide and should be page/value.

Current URL: http://localhost/kovusturma-sartlari/onodeme?dava=f2b80bf7

Expected URL: http://localhost/kovusturma-sartlari/onodeme/f2b80bf7

My Currently Rules:

            <rewrite>
                <rules>
                    <rule name="Add .php extension" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}.php" matchType="IsFile" />
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_URI}" pattern="^/home" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="{R:1}.php" />
                    </rule>
                    <rule name="Rewrite to /home" stopProcessing="true">
                        <match url="^(.*[^\]+)$" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="/home/{R:1}.php" />
                    </rule>
                </rules>
            </rewrite>

I Tried:

<rule name="Hide Query String" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="dava=(.+)" />
    </conditions>
    <action type="Rewrite" url="{R:0}/{C:1}" appendQueryString="false" />
</rule>

2

Answers


  1. Maybe try this?

    <rule name="Hide Query String" stopProcessing="true">
        <match url="^([^?]*)(?.*)*$" />
        <conditions>
            <add input="{QUERY_STRING}" pattern="dava=(.+)" />
        </conditions>
        <action type="Rewrite" url="{R:1}/{C:1}" appendQueryString="false" />
    </rule>
    
    Login or Signup to reply.
  2. You can refer to this article, the examples in the article will help you understand how to create the correct rewrite rules.

    If you want to hide the "dava" parameter for /kovusturma-sartlari/onodeme/ page, you can try the following rule:

    Current URL:
    http://localhost/kovusturma-sartlari/onodeme?dava=f2b80bf7

    Expected URL: http://localhost/kovusturma-sartlari/onodeme/f2b80bf7

    <rule name="Hide Query String">
        <match url="^kovusturma-sartlari/onodeme/([0-9a-z]+)" />
        <action type="Rewrite" url="kovusturma-sartlari/onodeme?dava={R:1}" />
    </rule>
    

    If the "dava" key needs to be hidden in the entire website, you need to modify the rule according to the specific situation of your website,like:

    <rule name="Hide Query String">
        <match url="(.*)/([0-9a-z]+)" />
        <action type="Rewrite" url="{R:1}?dava={R:2}" />
    </rule>
    

    Also, when you have problems with IIS rewrite rules, you can try using Failed Request Tracing to trace rewrite rules for troubleshooting, and you can see how the rules are used internally.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search