New to apache having rewrite rule problem please help

Posted on 2004-11-28
Last Modified: 2010-03-04
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


to output as


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
Question by:mediatimebomb
    LVL 18

    Expert Comment


    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 =)
    LVL 48

    Accepted Solution

    Try this rewrite-Rule:

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

    This will rewrite

    Author Comment

    thanks for you help
    LVL 18

    Expert Comment

    What ?! That's exactly what I said.  Except I said it first.  And explained why.
    LVL 48

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now