• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

New to apache having rewrite rule problem please help

After 3 solid days i have managed to get apache with mod_rewrite installed with php.

Not bad for a coldfusion / iis guy

However i am having problems getting a mod_rewrite rule to work

I know it is working because this simple rule processes no problem

RewriteRule ^foo.html bar.html [R,L]

however when i try to rewrite the folloing url

http://localhost/playhere.php?info=heli-tours.html

to output as

http://localhost/playhere/info/heli-tours.html

I have no luck page not found?

I have tried to following combinations with no success

RewriteRule ^playhere/(.*)/(.*)/$ playhere.php?$1=$2
RewriteRule /playhere/(.*)/(.*)/$ /playhere.php?$1=$2
RewriteRule playhere/(.*)/(.*)/$ /playhere.php?$1=$2

also do you need to restart apache after modifing the .htaccess file?

Any help with this issue would be of great assistance and be much appreciated

thank you in advance
0
mediatimebomb
Asked:
mediatimebomb
  • 2
  • 2
1 Solution
 
arantiusCommented:
mediatimebomb,

What version of apache are you using?  Your problem is "greedy wildcards" and it cna be solved more directly in apache 2 which has stronger regex support.  In short, your first .* is matching everything because that's how wildcards work in regular expressions.

In apache 2, use (.*?) as a non-greedy operator instead of (.*).  In 1, you have to go a little backwards.  use: ([^/]*) .  This matches any number of characters that are not a slash.  Which is what you want =)
0
 
hernst42Commented:
Try this rewrite-Rule:

RewriteRule ^playhere/([^/]+)/(.*)$ playhere.php?$1=$2

This will rewrite
http://localhost/playhere/info/heli-tours.html
to
http://localhost/playhere.php?info=heli-tours.html
0
 
mediatimebombAuthor Commented:
thanks for you help
0
 
arantiusCommented:
What ?! That's exactly what I said.  Except I said it first.  And explained why.
0
 
hernst42Commented:
I haven't read your comment while I was trying to solve that problem (needed 20 min to setup my apache and get mod_rewrite to work). My reg-ex does not rely on greedines or not.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now