简体   繁体   English

重写规则在PHP的IIS服务器中不起作用

[英]Rewrite Rule not Working in IIS Server with PHP

Hi, friends. 朋友们 I'm creating an .htaccess file with rewrite rules. 我正在创建带有重写规则的.htaccess文件。 It's working fine in localhost, but on the live, server it's not working. 它在localhost中可以正常工作,但是在实时服务器上却无法正常工作。 My hosting uses a Window server. 我的托管使用Window服务器。

I wrote this Rule in my .htaccess file: 我在.htaccess文件中写了此规则:

RewriteEngine On
RewriteBase /project_name/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$

RewriteRule (.*) pages.php?page_slug=$1 [L]

For the case of wordpress to run on IIS server , you need to create web.config in root directory then put the code below, 对于wordpress在IIS服务器上运行的情况,您需要在根目录中创建web.config,然后将代码放在下面,

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="wordpress" 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" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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