简体   繁体   English

在Web.config中将Gallery3 .htaccess mod_rewrite代码转换为IIS URL重写

[英]Converting Gallery3 .htaccess mod_rewrite code to IIS URL Rewrite in Web.config

I have a website on which i have installed Gallery3. 我有一个已安装Gallery3的网站。 The url is 该网址是

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

But when i open the "test album", in the url there is index.php 但是当我打开“测试相册”时,URL中有index.php

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

Now what i want is to remove the index.php from the url and want the url to look like this 现在我想要的是从网址中删除index.php,并希望该网址看起来像这样

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

Since my shared server space is a windows platform with IIS 7, i cant use the .htaccess file. 由于我的共享服务器空间是带有IIS 7的Windows平台,因此我无法使用.htaccess文件。 Since my server got Microsoft URL Rewrite module installed i need to write the rewrite rule in web.config file. 由于我的服务器安装了Microsoft URL重写模块,因此我需要在web.config文件中写入重写规则。

This is the code for hiding the index.php in the .htaccess file 这是用于在.htaccess文件中隐藏index.php的代码

 <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>

I tried to convert this by installing the Microsoft URL Rewrite module in my localhost. 我试图通过在本地主机中安装Microsoft URL Rewrite模块来进行转换。

Except the "RewriteBase /gallery" all the other codes get converted ."RewriteBase /gallery is not converted because it is not supported by IIS" is the error message i got. 除了“ RewriteBase / gallery”以外,其他所有代码都已转换。“ RewriteBase / gallery未转换,因为它不受IIS支持”是我收到的错误消息。 And this is the converted code. 这是转换后的代码。

<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>

But it seems this code is not working as the index.php is still there. 但是似乎此代码无法正常工作,因为index.php仍然存在。 The ISS URL Rewrite Module is working since another rule "Enforce canonical hostname" which i added in the web.config is working properly. ISS URL重写模块正在运行,因为我在web.config中添加的另一个规则“强制规范主机名”正在正常运行。

This is my complete web.config file. 这是我完整的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>

So where is the problem??. 那么问题出在哪里呢? What should be done to remove the index.php from the url?? 从URL中删除index.php应该怎么做? Please help me sort this out. 请帮我解决这个问题。

This may have to do with where 1 you place this Web.config file. 这可能与放置此Web.config文件的位置1有关 As long as it is in the http://www.MovieGa.com/gallery/ subdirectory, I think it should work...! 只要它位于http://www.MovieGa.com/gallery/子目录中,我认为它就可以工作...!

EDIT: In response to your second question, here is probably why that error is happening: 编辑:针对您的第二个问题,这可能是为什么发生此错误的原因:

It has to do with this part: 它与以下部分有关:

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

With .htaccess, I think this works fine. 使用.htaccess,我认为这很好用。 But with Web.config , it gives you that error because 2 it's trying to find capture groups in regex while there are none in this particular <match url="^$"> section. 但是使用Web.config ,它会给您该错误,因为2它试图在正则表达式中查找捕获组,而在此特定的<match url="^$">部分中则没有任何捕获组。 If you remove that ?kohana_uri={R:1} part from the url="" , does it work? 如果您从url=""删除那个?kohana_uri={R:1}部分,它可以工作吗?

Reference: 参考:

1 http://forums.iis.net/t/1162232.aspx (Anil Ruia's comment) 1 http://forums.iis.net/t/1162232.aspx(Anil Ruia的评论)

2 http://forums.iis.net/t/1150904.aspx (ruslany's second comment) 2 http://forums.iis.net/t/1150904.aspx(ruslany的第二条评论)

Ok i will make things clear here,for those who are installing gallery 3 in Windows Server with IIS7 and are trying to get rid of the index.php file from the url. 好的,对于那些在IIS7的Windows Server中安装Gallery 3并试图摆脱url中的index.php文件的人,我将在这里说清楚。

1st : Keep your web.config file with the rewrite rules in the directory where you are installing gallery and not the root of your website 1st:将带有重写规则的web.config文件保留在要安装Gallery的目录中,而不是网站的根目录中

2nd : The rewrite rules of the web.config file that you are placing inside the gallery folder should be like this 第二:您要放置在gallery文件夹中的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>

Hope this will be useful for others who are facing the same problems like the one i encountered.. 希望这对其他遇到相同问题的人很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM