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