Forum Moderators: phranque

Message Too Old, No Replies

Wrong variable value in redirect

         

Mister_L

11:50 am on Sep 2, 2009 (gmt 0)

10+ Year Member



Hi,

I have a folder called brands with the following htaccess file:

Options FollowSymLinks

RewriteEngine On
RewriteRule ^(product)-([^-]+)\.html$ ../product.php?product_type=machine&id=$2 [L]
RewriteRule ^(.*)-([^-]+)\.html$ ../category.php?link_from=$1&page=$2 [L]

When I click on <a href="brands/name-1.html">name</a>
I get that link_from=name name.

Does anyone know why that happens?

In my other sites I used the exact same method and it worked just fine.

Thanks.

[edited by: jdMorgan at 12:19 pm (utc) on Sep. 2, 2009]
[edit reason] Tidied up. [/edit]

jdMorgan

12:21 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When I click on <a href="brands/name-1.html">name</a>
I get that link_from=name name.

This is not clear. What do you *want* to happen?

Jim

Mister_L

1:13 pm on Sep 2, 2009 (gmt 0)

10+ Year Member



link_from is supposed to get the value "name" instead of "name name",isn't it?

jdMorgan

1:39 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I don't know, because I don't know anything about your site or your intent. Also, since you did not quote that string in your post, it was not entirely clear that the value of of "link_from" was "name name" -- That is, the second "name" could have been referring to the function of (or "your label" for) the name/value pair.

This is a very strange result. I don't see anything in the code you posted that would certainly cause this problem. I do note, however, that you're using "../" as a destination path. I'd recommend that you provide a fully-rooted path instead, e.g. "/category.php?link_from=$1&page=$2" instead of "../category.php?link_from=$1&page=$2"

Also, look for other rules in this .htaccess file and in the root directory's .htaccess file which may rewrite this rule's input path before this rule executes, or which may re-rewrite this rule's output path after this rule executes... Remember that mod_rewrite in a .htaccess context is effectively recursive, and execution of mod_rewrite will be re-started every time any rule has been invoked. This can lead to "infinite loops," or --as in this case-- unexpected operation.

Jim