2012-01-21 148 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> 

希望这将是为别人谁正面临着像我遇到了一个同样的问题有用..