在一个子目录URL重写

在一个子目录URL重写

本文介绍了在一个子目录URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Restler构建REST API的Apache服务器上,我有一些URL重写的问题。
这里是我的目录:

I'm using Restler for building REST API on an Apache Server and I have some url rewrite problems.
Here are my directories :

/ API:
   /供应商
   ...
   的.htaccess(第一级)
   /市民:
     /例子
     /测试
     / src目录
     的.htaccess(2级)
     /浏览器:
       / CSS
       /图像
       / lib目录
       index.html的

/api:
  /vendor
  ...
  .htaccess (1st level)
  /public :
    /examples
    /test
    /src
    .htaccess (2nd level)
    /explorer :
      /css
      /images
      /lib
      index.html

现在,这里就是我想:
1)我希望有一个看不见的公共与其他目录。
例如像一个请求获取mydomain.com/api/data 将直接挑入 mydomain.com/api/public/data

2)我想公共目录的根目录是浏览器/ index.html的,但这个文件中加载了大量资源以相对的方式,有时它不会加载。

Now, here is what I want :
1) I want an invisible "public" directory from the others.
For example a request like GET mydomain.com/api/data will pick it directly into mydomain.com/api/public/data

2) I want the root of "public" directory to be explorer/index.html but this file load a lot of resources in a relative way and sometimes it don't load.

所以基本上我想获得/api/public/explorer/index.html所有加载如果我只尝试访问资源: mydomain.com/api

So basically I want to access to /api/public/explorer/index.html with all the resources loaded if I only try to access to : mydomain.com/api

下面是我现在:

Here is what I have now :

Options +FollowSymLinks
AddDefaultCharset UTF-8

RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_URI} !^public/
RewriteRule ^(.*)$ /api/public/$1

对于第一级的.htaccess,这似乎工作pretty的好

For the first-level .htaccess, which seems to works pretty well

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/$ explorer/ [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
    php_flag display_errors On
</IfModule>

有关的第二级别的.htaccess

For the second-level .htaccess

任何recommandations?谢谢

Any recommandations ? Thank you

推荐答案

这条规则:

RewriteRule ^/$ explorer/ [QSA,L]

是行不通的,因为达到这一规定的请求将有领先的斜线剥离:

Isn't going to work, because requests that reach that rule will have the leading slash stripped off:

RewriteRule ^$ explorer/ [QSA,L]

但我不能完全确定这就是你想要任何东西,因为为了得到这条规则,你需要去:

But I'm not exactly sure that's what you want either, because in order to get to that rule, you'd need to go to:

http://mydomain.com/api/

如果这就是你想要的东西,那么你只需要删除斜线。

If that's what you want, then you just need to remove that leading slash.

这篇关于在一个子目录URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:08