有人能帮我制定这个应用程序格式的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
因此,我基本上想要从root.htaccess文件:
- 将所有以"/api/"开头的流量重定向到"/api/*"。这包括所有资产
- 所有其他流量转到"/src/*"。
- 在/src/.htaccess中:我需要所有的文件请求像往常一样在/src中查找,但所有的url请求都只需转到index.html(RewriteRule^index.html[L])
还有另一个我喜欢的好功能:
- url:mydomain.com/api/relatest链接到一个预定义的文件夹(例如/api/1.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]