views:

46

answers:

3

Can anyone spot what is wrong with this URL rewrite? I can't get it to pass anything to GET (the script loads, but no parameters are passed):

RewriteRule ^archive(/(.*))?$ archive.php?action=$1 [QSA,L]

I want to map "archive/browse/" to "archive.php?action=browse".

A: 
RewriteRule ^archive/([^/]*) archive.php?action=$1 [QSA,L]
Havenard
+3  A: 

You can get some conflicts when MultiViews is enabled. If it’s enabled, Apache first tries to find a file with a similar name to map the request to before passing it down to mod_rewrite. So a request of /archive/browse/ ends in /archive.php/browse/ before mod_rewrite can map it to your /archive.php?action=browse.

Try to disable it with:

Options -MultiViews
Gumbo
The inner group is still $1?
Vinko Vrsalovic
Although if nothing is passed, your scenario makes more sense
Vinko Vrsalovic
@Vinko Vrsalovic: The option doesn’t change anything concerning mod_rewrite. It just stops Apache from looking for similar named files. Another solution would be to rename the file, if MultiViews is really the cause of this behavior.
Gumbo
I know, I was asking about (/(.*)), is the inner group still $1?
Vinko Vrsalovic
@Vinko Vrsalovic: No, that’s `$2`. But he said nothing gets passed, so I don’t think it’s the rule.
Gumbo
+1  A: 
RewriteEngine On
RewriteRule ^archive/(.*)$  archive.php?action=$1 [QSA,L]

Would rewrite anything after /archive/ to archive.php?action=test/dir/path

Chacha102