Forum Moderators: phranque

Message Too Old, No Replies

weird htaccess making me crazy

only one rule works out all rules

         

phparion

11:40 pm on Oct 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,

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.

jdMorgan

12:17 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you get the 404 error, what is in your server error log? Check the filepath carefully, and see if it is incorrect or not.

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

phparion

12:23 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



:( ... sometimes, when you are concentrating hard on something you become blind to see simple things. The htaccess file I was changing was the wrong file and not the one affecting site :-s

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 :)

g1smd

8:16 am on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might also now want to think about adding a redirect such that if someone asks for URLs like example.com/index.php?controller=feed&view=addFeed they are redirected to the canonical URL for that content.

phparion

2:38 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



would it not start running into a loop?

bad URL -> SEF URL
SEF URL -> bad URL

jdMorgan

3:06 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using your terms, but improving the specifics, let me clarify:

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

g1smd

8:05 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A rewrite silently fetches a file from somewhere in the internal filesystem.

A redirect suggests that to the browser that it makes a new request for a different URL.

Understanding the difference between those two things is crucial.