【问题标题】:.htaccess multiple folders and root.htaccess 多个文件夹和根目录
【发布时间】:2014-09-22 08:41:20
【问题描述】:

有人可以帮我制定此应用程序格式的 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/*”。
    • 在 /src/.htaccess 中:我需要像往常一样查看 /src 中的所有文件请求,但所有 url 请求只需转到 index.html (RewriteRule ^ index.html [L])。

还有一个我很喜欢的好功能:

  • url: mydomain.com/api/latest 链接到预定义文件夹(例如 /api/1.0),或者是否有办法从文件夹名称中找到最新版本号(但让它计算这可能是太多的处理能力,因为它很容易被硬编码,并且会有很多请求)。

任何帮助表示赞赏。 提前致谢。

【问题讨论】:

    标签: php angularjs apache .htaccess mod-rewrite


    【解决方案1】:

    我自己制定了解决方案,但有人可以发表评论,让我知道这是否好(可行),或者是否有更好的解决方案。

    干杯。

    /.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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2012-10-23
      • 1970-01-01
      • 2012-02-27
      • 2017-01-29
      • 2021-09-03
      • 2011-01-19
      相关资源
      最近更新 更多