CodeIgniter .htaccess rewrite paths


CodeIgniter .htaccess rewrite paths

我正在使用codeIgniter作为我的家庭项目,运行一个angularJS(yeoman)应用程序作为前端。CI 已针对 HMVC 结构进行了配置,并且工作正常。

我的主要问题是根据环境变量将一些目录重写到实际位置。

这是我尝试过的htaccess规则(这是整个.htaccess):

RewriteCond %{HTTP_HOST} ^movieapp.ds$
RewriteRule (.*) $1 [E=ENVIRONMENT:development]
#Redirects frontend app requests
RewriteCond %{ENV:ENVIRONMENT} ^development$
RewriteRule ^scripts/(.*)$ app/scripts/$1 [L]
RewriteRule ^styles/(.*)$ app/styles/$1 [L]
RewriteRule ^images/(.*)$ app/images/$1 [L]
RewriteRule ^views/(.*)$ app/views/$1 [L]

RewriteCond %{ENV:ENVIRONMENT} ^production$
RewriteRule ^scripts/(.*)$ dist/scripts/$1 [L]
RewriteRule ^styles/(.*)$ dist/styles/$1 [L]
RewriteRule ^images/(.*)$ dist/images/$1 [L]
RewriteRule ^views/(.*)$ dist/views/$1 [L]

文件夹结构

  • /应用
  • /app - AngularJS 应用程序正在开发中
    • /脚本
    • /风格
  • /系统
  • /dist
    • /脚本
    • /风格

我想根据环境变量将 example.com/scripts/* 请求重定向到应用程序/脚本或 dist/脚本。

如您所见,我不是.htaccess专家,所以当您发布答案时,请保持困难,就像猴子可以解释它一样。

提前致谢

我不能谈论整个.htaccess,以及你想要获得的功能,但是这些RewriteRule并没有做你所期望的,因为标志[L]。它的意思是"最后"。遇到第一个"最后一个"标志,停止重写过程,不读取其他规则。在这种情况下,您可以删除标志。有关此 apache 文档页面中标志的更多信息。将页面一直向下滚动,以找到它。