htaccess rules

Posted on 2007-10-20
Last Modified: 2008-08-29
I have a rule like that

RewriteRule ^categories/([0-9]+)/(.+)/([0-9]+)/$ categories.php?category_id=$1&page=$3
The $_GET variable does not include $page.
so I tried:
RewriteRule ^categories/([0-9]+)/([^/]+)/([0-9]+)/$ categories.php?category_id=$1&page=$3
and still it did not work
What I want is to be translated to$1&item_id=2
What do I do wrong ?

Question by:yudazdk
    LVL 50

    Expert Comment

    by:Steve Bink
    The page name is going to start with '/', most likely.  You are not including that in your rule.

    RewriteRule ^/categories/([0-9]+)/([^/]+)/([0-9]+)/$ /categories.php?cat_id=$1&item_id=$3

    Also, your rule requires a final slash.  This means the URL to trigger it must be:

    LVL 48

    Expert Comment

    > The page name is going to start with '/', most likely.  You are not including that in your rule.
    This only applies if the RewriteRule is used inside a Directory Tag. When used inside a .htaccess the Location does not start with a slash

    You can try:
    RewriteRule ^categories/([0-9]+)/([^/]+)/([0-9]+)/?$ categories.php?category_id=$1&page=$3 [L]
    Have you installed the suhosin extension on that server ?
    LVL 48

    Expert Comment

    So I played a little bit and here seems to be a problem with an apache module. The following worked for me:

    RewriteEngine On
    RewriteBase /~hernst/ee/22906835/
    RewriteRule ^categories/([0-9]+)/[^/]+/([0-9]+)$ cats.php?category_id=$1&page=$2

    I need to name the php-file cats.php instead of categories.php. If the php-file is name categories.php it doesn't work, because apache is using that file directly and not using the rewite rule. Don't know why this is the case.

    So if you name your categories.php to cats.php it should work.
    LVL 50

    Accepted Solution

    >>> This only applies if the RewriteRule is used inside a Directory Tag.

    I'm not quite sure I grasp how mod_rewrite is acting in the context of this rule...I'll have to play with it some, I guess.  Thanks for the clarification.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    760 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

    11 Experts available now in Live!

    Get 1:1 Help Now