2012-04-01 23 views

Trả lời

14

Bạn có thể thêm quy tắc viết lại trong tệp web.config của mình. Thêm dòng sau vào phần 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

Cảm ơn, nó hoạt động hoàn hảo :) – Rbeuque74

+0

Cài đặt này sẽ hoạt động trên hầu hết các khung php (zend 1/2, laravel, v.v.) –

+0

Điều này không hiệu quả đối với tôi và sau đó tôi nhận ra rằng tôi đã chuyển tham chiếu đến index.php của mình tập tin vào trong một thư mục ứng dụng (cho Codeigniter) vì vậy có lẽ một điều tốt cần nhớ là tệp này sẽ là nơi tệp index.php dành cho bạn. – Dusan

10

Tạo một web.config tên tập tin trong 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

Bạn cũng có thể thực hiện viết lại quy tắc khác như

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

với một điều kiện, là thay đổi $ config ['url_protocal'] = 'PATH_INFO'; trong config/config.php, điều này sẽ báo cho mô-đun viết lại URL sử dụng URI được ghi lại thay vì URL gốc, nếu không bạn sẽ gặp phải vấn đề 404 trang không tìm thấy.

Các vấn đề liên quan