Forum Moderators: phranque
I have been stuck in a rewrite problem. i have following .htaccess
RewriteEngine On
RewriteRule ^login/$ index.php?controller=login&view=login [L]
RewriteRule ^process/$ index.php?controller=action&opt=login [L]
RewriteRule ^feeds/view-all/$ index.php?controller=feed&view=viewAll [L]
RewriteRule ^feeds/add/$ index.php?controller=feed&view=addFeed [L]
My this .htaccess and application is present in a folder at
www.example.com/apps/appname/
Now the problem is that only first RewriteRule, www.example.com/apps/appname/login/, works and all others give 404 page not found error.
even if I copy the working RewriteRule as
RewriteRule ^login2/$ index.php?controller=login&view=login [L]
and visit
www.example.com/apps/appname/login2/
I get 404 error.
However, this rule works
RewriteRule ^index.html$ index.php [L]
it redirects /index.html to index.php
I tried clearing my cache etc but nothing makes my other URLs work.
Any help is much appreciated to sort this out.
If it's incorrect, consider that the substitution path in your rules may need to be "/apps/index.php?controller=..." instead of just "index.php?controller=..."
This may not be the actual problem, so it is well worth checking that error log.
Jim
I am making a simplified MVC framework for my new project with PHP5 OOP. I was concentrating hard on details. I took an hour break, listened to a few songs, got back and solved it :)
Non-SEF (URL-path) received directly from client --301 redirect--> SEF URL
Non-SEF (filepath) resulting from internal rewrite --> do nothing, proceed to content-handling
SEF-URL --internal rewrite-> Non-SEF filepath
All it requires is that you use a RewriteCond to examine THE_REQUEST in the first-listed step to disable that first rule if the non-SEF request didn't come from the client.
So you need two rules: A first rule to externally redirect non-SEF URL-path requests to SEF URLs if the non-SEF URL request comes from the client, and a second rule to internally rewrite SEF URL requests to the non-SEF internal filepath. The second case in my list occurs by default, so only two rules are needed.
Jim