简体   繁体   中英

Translating .htaccess to web.config

I am hosting a php application on my virtual Windows server running IIS.

The person who wrote the php website for me asked me to put this piece of codes in a .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

But as this application is running on IIS, I need to translate this piece of codes to web.config. How can I translate them into web.config?

What this htaccess code does is redirecting any requests which would otherwise result in a 404 error (!-f and !-d mean "file does not exist" and "dir does not exist") to /index.php.

IIS7 has a feature to import mod_rewrite rules - simply use this:

  1. Start IIS Manager.
  2. On the left, in the Connections pane, select Default Web Site.
  3. On the right, in Features View, click URL Rewrite.
  4. On the right, in the Actions pane, click Import Rules.
  5. Copy your mod_rewrite rules and paste them into the Rewrite rules text box.
  6. The Tree View tab of the Converted Rules box instantly shows the result of the conversion. You can also click the XML View tab to see how the rules are stored in the Web.config file.

( Source )

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