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

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 ?

0
yudazdk
Asked:
yudazdk
  • 2
  • 2
1 Solution
 
Steve BinkCommented:
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/
0
 
hernst42Commented:
> 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 ?
0
 
hernst42Commented:
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.
0
 
Steve BinkCommented:
>>> 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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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