【问题标题】:Apache2 rewrite urlApache2重写网址
【发布时间】:2012-11-27 19:25:00
【问题描述】:

我对这些 apache2 重写感到困惑。

我需要创建一个 REST 接口,我当然可以在其中使用真实的 URL。 我在 localhost atm 进行测试。

http://localhost/ssase12/services/users/
http://localhost/ssase12/services/users

应该发给

http://localhost/index.php?rt=index/users

所以我需要检测 3. 文件夹/名称并将其重定向到上面的链接 - users = $1。

有意义吗? 我试图用放置在用户文件夹中的 .htaccess 来做到这一点......我可以从服务文件夹中做到这一点吗?所以一切都写在

之后
http://localhost/ssase12/services/blah(/) 

也会发送吗?

谢谢

【问题讨论】:

    标签: rest mod-rewrite apache2


    【解决方案1】:

    您可以将规则放在文档根目录中

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ssase12/services/(.*?)/?$ /index.php?rt=index/$1 [L]
    

    或 ssase12 目录:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^services/(.*?)/?$ /index.php?rt=index/$1 [L]
    

    或服务目录。

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*?)/?$ /index.php?rt=index/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2010-10-08
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 2011-03-22
      • 2015-04-12
      • 2014-03-09
      • 1970-01-01
      相关资源
      最近更新 更多