.htaccess:让RewriteCond检查“ api”字符串是否存在,然后重定向到api文件夹,否则重定向到Web /索引文件?

时间:2018-09-14 05:27:21

标签: php .htaccess redirect

我有一个如下所示的文件夹目录。该请求来自访问,如果URL中包含API字符串,则我想在请求上写一个条件,然后重定向到api/index.php,否则重定向到web/index.php

root
 + api
  +index.php
 +web
   +index.php
 +.htaccess

我现在的htaccess为

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>

<IfModule mod_rewrite.c>
 RewriteCond %{REQUEST_URI} ^(.*)api(.*)$
 RewriteRule ^(.*)$ api/index.php/$1 [L]

 RewriteCond %{REQUEST_URI} ^/.*
 RewriteRule ^(.*)$ web/$1 [L]

 RewriteCond %{REQUEST_URI} ^/(assets|css|js|img|uploads)
 RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
 RewriteRule ^css/(.*)$ /web/css/$1 [L]
 RewriteRule ^js/(.*)$ /web/js/$1 [L]
 RewriteRule ^img/(.*)$ /web/img/$1 [L]
 RewriteRule ^uploads/(.*)$ /web/uplods/$1 [L]
 RewriteRule ^frontAssets/(.*)$ /web/frontAssets/$1 [L]

 RewriteCond %{REQUEST_URI} !^/web/(assets|css|js|img|uploads)/
 RewriteCond %{REQUEST_URI} !index.php
 RewriteCond %{REQUEST_FILENAME} !-f [OR]
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteRule ^.*$ web/index.php

0 个答案:

没有答案