2012-01-21 69 views
1

我有一個網站,我已經安裝了Gallery3。網址是將Gallery3 .htaccess mod_rewrite代碼轉換爲IIS URL在Web.config中重寫

http://techblog.lalsofttech.com/gallery/ 

但是當我打開「測試專輯」,在URL中存在的index.php

http://techblog.lalsofttech.com/gallery/index.php/test 

現在我想的是從URL中刪除index.php文件和想要的網址看起來像這樣

http://techblog.lalsofttech.com/gallery/test 

因爲我的共享服務器空間是一個Windows平臺的IIS 7,我不能使用.htaccess文件。 由於我的服務器得到了Microsoft URL重寫模塊安裝,我需要在web.config文件中寫入重寫規則。

這是隱藏的index.php .htaccess文件中

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteBase /gallery 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L] 
    RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L] 
    RewriteRule ^index.php/(.*) $1 [QSA,R,L] 
</IfModule> 

我想在我的本地安裝Microsoft URL重寫模塊轉換該代碼。

除了「RewriteBase/gallery」所有其他代碼被轉換之外,「RewriteBase/gallery沒有被轉換,因爲它不被IIS支持」是我得到的錯誤消息。 這是轉換後的代碼。

<rewrite> 
<rules> 
<rule name="Imported Rule 1" 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" /> 
    </conditions> 
    <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
</rule> 
<rule name="Imported Rule 2" stopProcessing="true"> 
    <match url="^$" ignoreCase="false" /> 
    <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
</rule> 
<rule name="Imported Rule 3" stopProcessing="true"> 
    <match url="^index.php/(.*)" ignoreCase="false" /> 
    <action type="Redirect" redirectType="Found" url="{R:1}" appendQueryString="true" /> 
</rule> 
</rules> 
</rewrite> 

但它似乎代碼不工作,因爲index.php仍然存在。 ISS URL重寫模塊正在工作,因爲我在web.config中添加的另一個規則「強制規範主機名」工作正常。

這是我完整的web.config文件。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
<system.webServer> 
    <directoryBrowse enabled="false" /> 
    <rewrite> 
    <rules> 
    <rule name="Enforce canonical hostname" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.moviega\.com$" /> 
     </conditions> 
     <action type="Redirect" url="http://www.moviega.com/{R:1}" redirectType="Permanent" /> 
    </rule> 
    <rule name="Imported Rule 1" 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" /> 
     </conditions> 
     <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
    </rule> 
    <rule name="Imported Rule 2" stopProcessing="true"> 
     <match url="^$" ignoreCase="false" /> 
     <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
    </rule> 
    <rule name="Imported Rule 3" stopProcessing="true"> 
     <match url="^index.php/(.*)" ignoreCase="false" /> 
     <action type="Redirect" redirectType="Found" url="{R:1}" appendQueryString="true" /> 
    </rule> 
    </rules> 
</rewrite> 
</system.webServer> 
</configuration> 

那麼問題在哪裏?應該做什麼從url中刪除index.php? 請幫我解決這個問題。

回答

0

這可能與您放置此Web.config文件的位置有關。只要它在http://www.MovieGa.com/gallery/子目錄中,我認爲它應該工作...!

編輯: 在回答你的第二個問題,這裏大概是爲什麼發生錯誤的:

它做這部分:

<rule name="Imported Rule 2" stopProcessing="true"> 
    <match url="^$" ignoreCase="false" /> 
    <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
</rule> 

隨着的.htaccess,我認爲這工作正常。但與Web.config,它給你這個錯誤,因爲它試圖在正則表達式中找到捕獲組,而在這個特定的<match url="^$">部分沒有。如果您從url=""中刪除?kohana_uri={R:1}部件,它是否工作?

參考:

http://forums.iis.net/t/1162232.aspx(阿尼爾魯亞的評論)

http://forums.iis.net/t/1150904.aspx(ruslany的第二個評論)

+0

,我已經做了,我已經張貼在這裏http://forums.iis.net/t/1186418.aspx但w如果我曾經訪問過我的網站,比如http://www.MovieGa.com/gallery/,則會出現另一個錯誤「HTTP錯誤500.50 - URL重寫模塊錯誤。 表達式「index.php?kohana_uri = {R:1}」無法展開「但是如果我在url中調用index.php頁面,一切正常,你可以看到我在這裏提到的錯誤http: //techblog.lalsofttech.com/Gallery/ – Shijilal

+0

我已經更新了上面的答案;從「導入的規則2」中取出'?kohana_uri = {R:1}'爲您工作嗎? – summea

+0

謝謝你解決了那個錯誤500問題..但再次有一個問題,在這個網頁http://techblog.lalsofttech.com/Gallery在這裏,如果我們移動任何相冊或鏈接的移動,你可以看到index.php將在那裏,這是不應該在那裏..像這樣http://techblog.lalsofttech.com/Gallery/index.php/test。如果我們點擊它,在index.php不會在那裏的下一頁網址,沒關係..但是在主頁的所有鏈接中顯示index.php並不好,不應該在那裏 – Shijilal

0

好的我將事情說清楚這裏,對於那些誰安裝畫廊3在Windows Server與IIS7 ,並試圖擺脫URL的index.php文件。

1:保持你的web.config文件與目錄重寫規則要安裝的畫廊,而不是你的網站的根

第二:您將在web.config文件的重寫規則畫廊內的文件夾應該是這樣的

<?xml version="1.0" ?> 
<configuration> 

<system.webServer> 

<rewrite> 
<rules> 
    <rule name="Imported Rule 1" 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" /> 
    </conditions> 
    <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
    </rule> 
    <rule name="Imported Rule 2" stopProcessing="true"> 
    <match url="^()$" ignoreCase="false" /> 
    <action type="Rewrite" url="index.php?kohana_uri={R:1}" appendQueryString="true" /> 
    </rule> 
    <rule name="Imported Rule 3" stopProcessing="true"> 
    <match url="^index.php/(.*)" ignoreCase="false" /> 
    <action type="Redirect" redirectType="Found" url="{R:1}" appendQueryString="true" /> 
    </rule> 
</rules> 
</rewrite> 

</system.webServer> 
</configuration> 

希望這將是爲別人誰正面臨着像我遇到了一個同樣的問題有用..