2012-04-01 63 views

回答

14

你可以在你的web.config文件中添加重写规则。添加以下到system.webServer部分:

<rewrite> 
    <rules> 
    <rule name="Rule" stopProcessing="true"> 
     <match url="^(.*)$" ignoreCase="false" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
     <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" /> 
    </rule> 
    </rules> 
</rewrite> 
+0

谢谢,它完美的作品:) – Rbeuque74 2012-04-02 07:46:30

+0

这个设置应该适用于大多数PHP框架(zend 1/2,laravel等) – 2014-09-17 01:03:58

+0

这不是为我工作,然后我意识到,我将参考移动到我的index.php文件保存在应用程序文件夹(对于Codeigniter)中,因此可能需要记住的一件好事是该文件应该是index.php文件适合您的位置。 – Dusan 2016-04-27 02:27:22

10

wwwroot中

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

创建一个文件名web.config中您也可以实现类似

<rule name="a rule"> 
<match url="^xxx/(.*)/(.*)-(.*)\.xxx" /> 
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> 
<action type="Rewrite" url="controller/method/{R:3}" /> 
</rule> 

其他重写规则有一个条件,是改变$ config ['url_protocal'] ='PATH_INFO';在config/config.php中,这将告诉URL重写模块使用重新编写的URI而不是原始URL,否则你将会有404页未找到问题。