简体   繁体   中英

Url Rewrite in a subdirectory

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


/vendor
...


/examples
/test
/src


/css
/images
/lib
index.html

Now, here is what I want :
1) I want an invisible "public" directory from the others.
For example a request like will pick it directly into 这样的请求将直接将其选择到

2) I want the root of "public" directory to be but this file load a lot of resources in a relative way and sometimes it don't load. 但是此文件以相对方式加载大量资源,有时却不加载。

So basically I want to access to /api/public/explorer/index.html with all the resources loaded if I only try to access to : 我想访问加载了所有资源的/api/public/explorer/index.html

Here is what I have now :

Options +FollowSymLinks
AddDefaultCharset UTF-8

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

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>

For the second-level .htaccess

Any recommandations ? Thank you

This rule:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM