restfull htaccess重写条件没有应用

时间:2016-12-27 09:18:52

标签: php ajax apache .htaccess mod-rewrite

我对规则有一些理解问题。它应该工作,但我想我错过了什么。帮助是Appriciated:)

规则:

<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteEngine On
  RewriteCond %{REQUEST_URI}$1 ^(.*?/)(.*)\2$
  RewriteRule ^(.*)$ - [E=BASE:%1]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule   %{ENV:BASE}^(.+)/(\w+?)/(\w+?)$       %{ENV:BASE}handler.php?path=$1&class=$2&method=$3 [L,QSA]

</IfModule>

将此网址转换为:

http://sccatdev.office.dig/deploy/ajax/Approval/Article/test

http://sccatdev.office.dig/deploy/ajax/handler.php?path=Approval&class=Artile&method=test以及帖子和获取。

但它似乎缺少某些东西。 .htaccess位于ajax文件夹中。

1 个答案:

答案 0 :(得分:0)

几乎没有问题:

    作为env变量的
  1. %{ENV:BASE}不能用于重写模式
  2. RewriteRule模式匹配相对于当前目录的URI,而不是完整路径匹配。
  3. 如果.htaccess位于ajax文件夹中,那么您甚至不需要%{ENV:BASE}变量来重写。只需使用以下.htaccess:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ handler.php?path=$1&class=$2&method=$3 [L,QSA]