views:

69

answers:

3

So, i've got this Zend style frontcontroller set up. Basically it just redirects every url back to index.

The urls are in the form of /controller/view/ + [additional parameters]

I would like to create some shortcuts in the following form:

RewriteRule ^home /home/index
RewriteRule ^products /products/view

RewriteRule .* index.php

However, mod_rewrite seems to be ignoring my rewrite rules. It doesn't alter home to home/index, even though i'm fairly certain that it should be able to catch that bit. So, i'm thinking it has got something to do with renaming request uri?

Here's the .htaccess file:

Options +FollowSymLinks
RewriteEngine on

RewriteRule  ^admin/  -  [L]
RewriteRule  ^media/  -  [L]

RewriteRule  ^home        home/index
RewriteRule  ^products    products/view

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
A: 

The following rule catches everything, so if its at the top it will never consider any other rules.

RewriteRule .* index.php

Try the following

Options +FollowSymLinks
RewriteEngine on

RewriteRule  ^admin/      -  [L]
RewriteRule  ^media/      -  [L]

RewriteRule  ^home        home/index [L]
RewriteRule  ^products    products/view [L]

RewriteCond  %{REQUEST_FILENAME} !-f
RewriteRule  .*           index.php
Fabian
Yeah, the 'redirect everything to index' bit is located only in the end. sorry about that. Still doesn't work though..
JHollanti
Could you add your entire .htaccess file, alot easier that way.
Fabian
Okay, edited it as a part of the question.
JHollanti
A: 

You might get problems when you try to rewrite everything that just begins with /home to /home/index as the latter does also begin with /home. You should use a more specific pattern like this:

RewriteRule ^home$ home/index
RewriteRule ^products$ products/view

But the rest should work fine.

Gumbo
Doesn't have any effect.
JHollanti
A: 

So far i've figured this much.

If you use the RewriteRule to alter your REQUEST_URI it doesn't actually alter REQUEST_URI, but another variable called REDIRECT_URI. That explains why nothng was happening.

Also, interestingly enough, i could do something like this:

RewriteRule ^products products/view [NC,L]

Something to this effect was was suggested by Fabian. He just appended index.php to the end, which didn't work for me. If i left that index.php out, everything worked perfectly. And somehow magically it redirects everything to index.php.

So for now, everything is working, but i haven't got a clue as to why everything is working. There's definitely an upvote for anyone who manages to explain what's happening here. Till then i think i'll just RTFM.

JHollanti