将web.config转换为.htaccess

时间:2016-06-23 10:53:16

标签: .htaccess mod-rewrite url-rewriting web-config

将此web.config转换为.htaccess的最佳方式是什么?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect App" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" pattern="api/(.*)" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="app/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

我的尝试如下:

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !api/(.*)
    RewriteRule ^ app/$1 [L]
</IfModule>

但是当我浏览api/(.*)时,/api无效。应该忽略它。

更新

在玩了一些并看了@ olaf-dietsche的回答后,我现在有了这个

<IfModule mod_rewrite.c>
    Options -MultiViews

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/api/
    RewriteRule /app%{REQUEST_URI} [L]
</IfModule>

但是,当我浏览/api时,我现在收到404错误。 /api在Apache中设置为别名,指向Laravel public目录。 404指出它无法找到public/index.php

别名设置如下

Alias /api /var/www/sites/WEBSITE-FOLDER/api/public

api/public中,.htaccess如下:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

0 个答案:

没有答案