php - CodeIgniter .htaccess rewrite paths
Get the solution ↓↓↓I'm using codeIgniter for my home project running an angularJS (yeoman) app as frontend. CI already configured for HMVC structure and works fine.
My main problem is to rewrite some directories to the actual location based on an environment variable.
Here's my htaccess rules I have tried (and here's the whole .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]
Folder structure
- /application
- /app - angularJS app in development
- /scripts
- /styles
- ...
- /system
- /dist
- /scripts
- /styles
- ...
And I'd like to redirect the example.com/scripts/* requests - based on the environment variable - to the app/scripts or dist/scripts.
As you see I'm not an .htaccess expert so please while you post an answer keep it difficult just like a monkey could interpret it.
Thanks in advance
Answer
Solution:
I can't talk about the whole .htaccess, and the functionality you want to obtain, but these RewriteRule(s) don't do what you expect, because of the flag [L]. It means "last". The first "last" flag met, stops the rewriting process, no other rule is read. In this case you may just delete the flags. More about the flags in this apache doc page. Roll the page all the way down, to find it.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.