1

I am passing parameters from one page to another page in PHP here is the code :-

<a href="index.php?product.php&category_id=<? echo $Getrow['id'];?>" target="_blank">Detail</a>

Now when i clicked on detail link it shows product page but at this page category_id is showing for example category_id=15 thus i don't want to show it rather then this id i want show category name using .htaccess please help me

I want its answer because when we pass query string like example.com/index.php?category_id=15&product_id=13 at this time someone can change it like example.com/index.php?category_id=156546565464654&product_id=13546545484 I don't want this thing.

sunena
  • 81
  • 7
  • 1
    This is not how htaccess works. – Lorenz Meyer Feb 08 '15 at 09:38
  • @LorenzMeyer means ? – sunena Feb 08 '15 at 09:41
  • 1
    Meaning, this won't work, unless you are hard-coding all your category names in your htaccess file. Better take care of this through PHP. – GolezTrol Feb 08 '15 at 09:42
  • @GolezTrol for your kind information Mr. GolezTrol this is not hard coded i looked at many websites that do the same thing as what i want i looked many tutorials but i was unable to understand. – sunena Feb 08 '15 at 09:50
  • Biting the hand that feeds you. I don't think you are in any position to call people here 'beginners', and if you think it's so simple, at least show *some* effort to solve it. Or are you just trolling, like in your other question? – GolezTrol Feb 08 '15 at 10:35

1 Answers1

0

I do something similar. When I create a link, I create the link in from of a text using variables, like <a href="category-15">click me</a>

Then in .taccess I do this

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)$ search.php?id=$2

and then the link http://example.com/category-15 takes me to http://example.com/search?id=15

I think, you can change the variables in the htaccess for your needs, you just need to use $1, $2, $3 etc for replacement. I hope this helps.

EDIT: I edited the example url, for consistency.

Hunnenkoenig
  • 193
  • 1
  • 2
  • 14
  • why you write here id=$2 here $2 means ? – sunena Feb 08 '15 at 10:05
  • ([a-zA-Z0-9_-]+) is the first regular expression (wildcard if you want) for changing the text and ([0-9]+) is the second. I pass a number in my text link, so I need to know that number. If I would use like http://example.com/category?id=15&product=34, then category would be $1 and product $2, but the wildcard must be partitioned the same way, so you would probably do something like `([a-zA-Z0-9_-]+)-([0-9]+)-([a-zA-Z0-9_-]+)-([0-9]+)` for `category-15-product-34`. The ^is the start of a string, the $ is the end of a string and has nothing to do with $1 etc. – Hunnenkoenig Feb 08 '15 at 10:12
  • @ Hunnenkoenig Options +FollowSymLinks RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)$ index.php?action=product_details&pid=$1 nothing happen ......... :-( – sunena Feb 08 '15 at 10:37
  • You need to understand that my example is tailored for my needs. You need to change the rewrite rule on your needs. I for my part put my links together from a title and a number I get from php as a variable. So my link would look like `myexample.com/this-is-a-very-nice-book-15` (I add the hyphens between the words by replacing space in code), but actually I want to show `myexample.com/search?id=15` now my link has two parts. A text part (which can also contain numbers) and a number part, which is always a number for the ID number I actually look for. -> -> – Hunnenkoenig Feb 08 '15 at 10:49
  • So my rewrite rule is ([a-zA-Z0-9_-]+) for the text part and ([0-9]+) for the number part. Two parts, two sets of wildcard. It seems you need to do the same. Because the link itself is your part 1 and the actual id is part two. So you need ` ^([a-zA-Z0-9_-]+)-([0-9]+)$ index.php?action=product_details&pid=$2` and pass a link as `myexample.com/myniceproduct-15` – Hunnenkoenig Feb 08 '15 at 10:53
  • But you need to reference the second wildcard with $2 because you want to use that. The $2 actually takes the original number that was passed. `([a-zA-Z0-9_-]+)` = $1 - `([0-9]+)` = $2 – Hunnenkoenig Feb 08 '15 at 10:55
  • example.com/index.php?category_id=15&product_id=13 would be `RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)-([a-zA-Z0-9_-]+)-([0-9]+)$ example.com/index.php?category_id=$2&product_id=$4` and that would give `example.com/mycategory-15-my-product-13` and nobody could change that, because no matter what he adds to the url, it always will take you to the url YOU passed in your code and nowhere else. – Hunnenkoenig Feb 08 '15 at 11:06
  • Of course you must format your links as `mycategory` and `my-product` or whatever you want, but in accordance to your rewrite rule. – Hunnenkoenig Feb 08 '15 at 11:16