简体   繁体   中英

IIS 10/Apache Issues - web.config

I am having issues with using the directory/variable rules that can be seen in languages various languages. For example:

http://example.com/foo/bar

should be read as example.com with foo and bar as variables.

However in IIS it does not seem to recognise this no matter how much rewriting I do. Here is the apache .htaccess file which works:

<IfModule mod_rewrite.c>
    Options -Multiviews
    RewriteEngine Options
    RewriteBase /richie/public
    RewriteCond %{REQUEST_FILENAME} "-d
    RewriteCond %{REQUEST_FILENAME} "-f
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

The converted/corresponding IIS web.config file in the public folder is as follows:

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

However IIS seems to be ignoring it... and I just get 404 because the directory does not exist (which it doesnt, hence the rewrite).

Any ideas?

When you specify the only file name in the rewritten URL without the path and hostname it will try to find the URL in the specific directory where you applied the rule. in your case it is trying to find the index.php file in the public folder and it is not available so you are getting 404 error instead of the index page. so just try to add the hostname in from of the index page in rewrite URL:

something like this:

http://www.example.com/index.php?url={R:1}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM