2014-02-16 18 views
0

我有Windows託管和網站是在PHP中。所以我問了託管公司我在哪裏可以找到.htaccess文件。他們說在Windows主機中沒有.htaccess文件,我必須使用web.config文件來進行網站配置。使用web.config和php

我試過這個簡單的代碼在我的web.config,但我得到500 - 內部服務器錯誤。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.web> 


    </system.web> 
    <rewrite> 
    <rule name="rule 1c" stopProcessing="true"> 
     <match url="^([a-zA-Z]+)$" /> 
     <action type="Rewrite" url="/index.php?category={R:1}" appendQueryString="true" /> 
    </rule> 
    </rewrite> 
</configuration> 

回答

0

這裏是web.config,我用來隱藏index.php,希望這會有所幫助。

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

斐伊川感謝您的回覆,但我得到了問題,如果用你的代碼,我嘗試另一種方式,因爲上的index.php我也有菜單

這裏的產品類別是代碼

它的工作時我寫作:mysite.com/sport(mysite.com/index.php?category=sport),mysite.com/clothes(mysite.com/index.php?category=clothes)等。

,但是當我寫作mysite.com/index時,它將視爲mysite.com/index.php?category=index

<rule name="Catagary" stopProcessing="true"> 
      <match url="^([a-zA-Z]+)$" ignoreCase="false" /> 
      <conditions> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 

      </conditions> 
      <action type="Rewrite" url="/index.php?category={R:1}" appendQueryString="true" /> 
     </rule> 

     <rule name="Gallery" stopProcessing="true"> 
      <match url="^([a-zA-Z0-9_-]+)$" ignoreCase="false" /> 
      <conditions> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
           </conditions> 
      <action type="Rewrite" url="gallery.php?id={R:1}" appendQueryString="true" /> 
     </rule> 

     <rule name="RewritePHP"> 
     <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="{R:1}.php" /> 
    </rule> 
</rules>