2014-09-22 182 views
0

有人可以帮我用这个应用程序格式的htaccess规则。.htaccess多个文件夹和根目录

这里是我的文件结构:

/api 
    - /1.0 (this is a php project, a backend rest api of sorts to the frontend) 
     - /other-php-folders 
      - /...(lots of stuff) 
     - /public 
      - /...(lots of assets etc) 
     - /index.php 
     - /.htaccess (ignore for now) 
/src (this contains an angularjs compiled website) 
    - /assets 
     - /cool-asset.js 
     - /cool-asset2.css 
     - /cool-asset3.png 
    - /index.html 
    - /.htaccess 
/.htaccess 

所以我基本上是从根.htaccess文件想:

  • 的所有流量重定向开始 “/ API /” 到“/ API/*”。这包括所有资产。
  • 所有其他流量转到“/ src/*”。
    • in /src/.htaccess:我需要像往常一样查看/ src中的所有文件请求,但所有url请求都只是转到index.html(RewriteRule^index.html [L])。

也是另一个不错的功能,我会爱:

  • 网址:(例如/api/1.0)mydomain.com/api/latest链接到预先定义的文件夹,或者如果有是一种从文件夹名称中查找最新版本号的方法(但是由于它可以很容易地进行硬编码并且会有很多请求,因此计算它可能会有太多的处理能力)。

任何帮助表示赞赏。 在此先感谢。

回答

0

我有点做了我自己的解决方案,但有人请评论,让我知道如果这是好的(它的工作),或者如果有更好的解决方案。

干杯。

/.htaccess

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !^/api 
RewriteRule ^(.*)$ /src/$1 [L] 

/src/.htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 
RewriteRule^index.html [L] 
相关问题