PHP, URL rewriting with htaccess, and Microsoft IIS Url Rewriting

后端 未结 4 1409
一个人的身影
一个人的身影 2021-01-01 03:04

I am used to working with Apache servers, so when mod_rewrite is enabled, I can create an htaccess file and use URL rewriting.

Here\'s my htaccess file:



        
相关标签:
4条回答
  • 2021-01-01 03:15

    The .htaccess file is an Apache convention for providing end-user access to Apache configuration, so you're not going to be able to use it as a drop in replacement on an IIS (Microsoft) server. You would be able to use it if you were running Apache on Windows.

    IIS7 has a URL rewriting module that offers support for rewriting URLs. There's also the ISAPI_Rewrite product which does the same for previous versions of IIS. You'll likely need some level of administrative permissions on the server to use either of these modules (i.e., no htaccess-like mechanism)

    0 讨论(0)
  • 2021-01-01 03:16

    You may use your above config as is in ISAPI_Rewrite 3 or Helicon Ape products.

    0 讨论(0)
  • 2021-01-01 03:20

    You can use your configuration as is, in Ionic's Isapi Rewrite Filter (IIRF).

    IIRF is free, open-source.

    0 讨论(0)
  • 2021-01-01 03:20

    If you use IIS 7 then you can use IIS URL Rewrite Module, that has an "Import Rules" feature that can be used to translate mod_rewrite rules to IIS URL rewrite format. These particular rewrite rules will not translate because the RewriteCond uses the "-s" and "-l" flags which check if the requested URL corresponds to a non-zero size file or to a symbolic link on a file system. If your application does not use any symbolic links then you can safely replace these conditions with:

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    

    and then convert the rules by using IIS URL Rewrite UI. That will result in these rules:

    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^.*$" />
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsFile"  />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory"  />
          </conditions>
          <action type="None" />
        </rule>
        <rule name="Imported Rule 2" stopProcessing="true">
          <match url="^.*$" />
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
    
    0 讨论(0)
提交回复
热议问题