繁体   English   中英

将web.config文件转换为.htaccess文件

[英]Convert web.config file to .htaccess file

我有一个web.config文件,我尝试转换为.htaccess并且它没有按预期工作。 我想帮助弄清楚我哪里出错了。

web.config中

<rewrite>
        <rules>
            <rule name="Redirect to https">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
            </rule>

            <rule name="Blocker" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{PATH_INFO}" pattern="^/version_" />
                </conditions>
                <action type="Redirect" url="https://www.example.com/404/" redirectType="Permanent" appendQueryString="false" />
            </rule>

            <rule name="API Director">
                <match url="(.*)" />
                <conditions>
                    <add input="{PATH_INFO}" pattern="^/api/v1/" />
                </conditions>
                <action type="Rewrite" url="/controller.php" />
            </rule>

            <rule name="HoverCart App" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <!--<add input="{HTTP_HOST}" pattern="^(.*)(quiverstest.)" />-->
                    <add input="{PATH_INFO}" pattern="^/newrelic/" negate="true" />
                </conditions>
                <action type="Rewrite" url="\app\{R:0}" />
            </rule>

        </rules>
    </rewrite>

的.htaccess

RewriteRule (.*)    https://{HTTP_HOST}{REQUEST_URI}

RewriteCond %{PATH_INFO} ^/version_
RewriteRule (.*)    https://www.example.com/404/

RewriteCond %{PATH_INFO} ^/api/v1/
RewriteRule (.*)    /controller.php

RewriteCond %{PATH_INFO} ^/newrelic/
RewriteRule .*    \app\$0

具体来说/ api / v1不起作用。 我试图进入https:// localhost / api / v1 / app /时得到404

说实话,我不太了解web.config或.htaccess,我正在尝试在最初为Windows机器制作的mac上设置一些东西。

编辑

我需要重写的最重要的规则就是这个

<rule name="API Director">
   <match url="(.*)" />
   <conditions>
     <add input="{PATH_INFO}" pattern="^/api/v1/" />
   </conditions>
   <action type="Rewrite" url="/controller.php" />
 </rule>

这是我得到的错误

The requested URL /api/v1/app/ was not found on this server.
Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.

这是一个相当粗糙的自动翻译你到那里。

  • 正则表达式规则应该很少进入RewriteConds:

     RewriteCond %{PATH_INFO} ^/api/v1/ RewriteRule (.*) /controller.php 

    应该只是:

     RewriteRule ^api/v1/ /controller.php 

    前导/应省略(来自任何^/… )。

  • Apache上下文中的环境引用需要%

     RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} ↑ ↑ 

    这个特别需要一个RewriteCond来匹配http://请求。

  • 很确定这些应该是正斜杠:

     RewriteRule .* \\app\\$0 ↑ ↑ 
  • 保留原始web.config中的注释

暂无
暂无

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

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