0

I don't think it is possible to add a PHP variable into the .htaccess file. Unless I am wrong?

My website creates content from a data base. I would like to change the URL to match what is being show.

I want to change,

http://domain.com/products

to

http://domain.com/products/brand/partnumber

I have php variables for $Brand and $Partnumber

How do I change the URL based on what is being show? Thanks in advance.

2
  • What do you mean "Change the URL" ? Like, redirect the client to a new page? Commented Jan 14, 2017 at 23:08
  • For SEO I figured it would be better that each product had it's own URL. I have a database with all the product information. I dynamically create the product pages just trying to update the URL so that it would match what is being shown. Commented Jan 15, 2017 at 16:46

1 Answer 1

1

Under products/index.php

<?php
 header("location: http://thisurl.com/products/".$brand."/".$partnumber);
?>

However, you may use a router, sth like http://github.com/klein/klein.php :

$klein->respond("/products/",function($request,$response){
   $response->redirect("/products/".$brand."/".$partnumber);
});
$klein->respond("/products/[:brand]/[:number]",function($request){
  return $request->brand." ".$request.number;
});

$klein->dispatch();
Sign up to request clarification or add additional context in comments.

2 Comments

I have been trying your top example. I keep running into an infinite loop. But I think this is the direction I need to go.
@brendan: the under example is even much better as you can easy extend/implement it. Thazs how i did it with all my projects

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.