Link to home
Start Free TrialLog in
Avatar of yudazdk
yudazdkFlag for Israel

asked on

htaccess rules

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 www.my-domain.com/categories/5/item-name/2 to be translated to
www.my-domain.com/categories.php?cat_id=$1&item_id=2
What do I do wrong ?

Avatar of Steve Bink
Steve Bink
Flag of United States of America image

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:

/categories/5/item-name/2/
> 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 ?
So I played a little bit and here seems to be a problem with an apache module. The following worked for me:

http://example.com/~hernst/ee/22906835/categories/55/item-name/3

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.
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial