2015-04-20 94 views
4

這是我的第一個PHP應用程序,我在本網站中同時使用了.html.php頁。如果用戶瀏覽mysite.com/users/?abc123,它將通過Ajax將成功加載id爲'abc123'的用戶的詳細信息在純html頁mysite.com/users/index.html上。現在,我的任務是從網址中刪除?,以便用戶瀏覽mysite.com/users/abc123,然後mysite.com/users/index.html?abc123應該成功地提供詳細信息。PHP:使用web.config重寫URL

我跟着this link並添加此規則,以我的web.config,但似乎並沒有工作,我收到:

Error: HTTP Error 404.0 - Not Found

<rule name="Remove question mark" patternSyntax="Wildcard" stopProcessing="true"> 
    <match url="*" /> 
    <conditions> 
    <add input="{HTTP_HOST}" pattern="^users/(.*)$" /> 
    </conditions> 
    <action type="Redirect" url="users/?{R:0}" redirectType="Permanent" /> 
</rule> 

請幫助我以下幾點考慮:

  1. 我只能用web.config中的URL重寫(讓事情變得簡單)
  2. 我想重寫URL爲名爲.html不.PHP(如果該事項)
  3. 我在本地IIS 8配置服務的PHP
+0

是否已安裝iis url重寫? http://www.iis.net/downloads/microsoft/url-rewrite – TheSk8rJesus

回答

1

這應該是工作

測試我的PHP的網站頁面
<rule name="Remove question mark" stopProcessing="true"> 
    <match url="^/?users/([^/]+)$" ignoreCase="true" /> 
    <conditions logicalGrouping="MatchAll"> 
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="https://stackoverflow.com/users/index.html?{R:1}" /> 
</rule> 
+1

這不起作用,當瀏覽http:// localhost:8080/users/abc123時,得到相同的* HTTP錯誤404.0 - 未找到*。 – theGeekster

+0

現在編輯代碼呢? –

+0

是的,非常感謝。一件小事......它會爲/ users和/ users /起作用嗎?我的意思是我需要爲兩者添加單獨的規則嗎? – theGeekster