【问题标题】:.htaccess IIS mod_rewrite.htaccess IIS mod_rewrite
【发布时间】:2017-05-24 07:10:37
【问题描述】:

我在 IIS mod_rewrite 模块中导入 .htaccess 文件时遇到问题。 出现 3 个错误。

.htaccess`

Options +FollowSymLinks -Indexes -MultiViews AddDefaultCharset UTF-8

<IfModule mod_rewrite.c> 
RewriteEngine On

##If your NeoFrag directory is not at http root
##you need to replace "/" by the correct directory, for example "RewriteBase /neofrag/"
RewriteBase /

##Allow direct access to specific directories
#RewriteCond %{REQUEST_URI} ^/(dir1|dir2)/
#RewriteRule .* - [L,QSA]

RewriteCond %{REQUEST_URI} !^/backups/

##Allow direct access to specific files
#RewriteCond %{REQUEST_FILENAME} /file1\.php [OR]
#RewriteCond %{REQUEST_FILENAME} /file2\.php [OR]

RewriteCond %{REQUEST_FILENAME} \.(png|jpg|jpeg|gif|swf|eot|svg|ttf|woff|woff2|zip)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L,QSA]

RewriteCond %{REQUEST_URI} \.html
RewriteRule (.*)\.html(.*) $1$2 [R=301,L]

RewriteRule .* index.php [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
</IfModule>

XML 视图

    <rewrite>
  <!--This directive was not converted because it is not supported by IIS: RewriteBase /.-->
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url=".*" ignoreCase="false" />
      <conditions>
        <add input="{URL}" pattern="^/(dir1|dir2)/" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <!--This rule was not converted because only some of the conditions are using the OR flag.-->
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url="(.*)\.html(.*)" ignoreCase="false" />
      <conditions>
        <add input="{URL}" pattern="\.html" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}{R:2}" />
    </rule>
    <!--The rule cannot be converted into an equivalent IIS format because of unsupported flags: E-->

有人可以帮我解决这 3 行错误吗?

  • RewriteBase /
  • RewriteRule .* - [L,QSA]
  • RewriteRule .* index.php [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]

【问题讨论】:

    标签: .htaccess mod-rewrite iis


    【解决方案1】:
    RewriteBase /
    

    您可以删除此行并在RewriteRule 上添加一个斜杠前缀替换。 IE。更改以下行:

    RewriteRule (.*)\.html(.*) $1$2 [R=301,L]
    RewriteRule .* index.php [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
    

    RewriteRule (.*)\.html(.*) /$1$2 [R=301,L]
    RewriteRule .* /index.php [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
    

    此规则未转换,因为只有部分条件使用 OR 标志

    转换器似乎正在尝试转换注释掉的代码??删除所有以#开头的行。

    RewriteRule .* /index.php [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
    

    E 标志设置环境变量。我不会说 IIS,但您可以删除上述指令中的 E=REMOTE_USER:%{HTTP:Authorization}, 部分,而使用 mod_setenvif(这会转换吗?)。例如,E 标志等价于:

    SetEnvIf Authorization "(.*)" REMOTE_USER=$1
    

    【讨论】:

    • 不客气!请将答案标记为已接受,以将其从未回答的问题队列中删除(左侧的复选标记)。一旦您拥有超过 15 个代表,您还可以对您认为有用的答案进行投票。谢谢,非常感谢。 :)
    • 该网站在页面上正常工作,但现在我们无法登录该网站并从该网站创建数据库条目。
    • 可能没有设置REMOTE_USER 环境变量?这段代码似乎可以转换吗?您在 (Web.)config 文件中看到了什么?
    猜你喜欢
    • 2011-01-12
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2017-12-04
    • 2012-11-05
    相关资源
    最近更新 更多