Ash Ash - 25 days ago 5x
Apache Configuration Question

Can an Apache .htaccess rewrite access a variable not contained in the URL

I assume this is not possible, but would like to double check.

If for example I had the URL:

I know using basic rewrite rules I can change the URL to anything using the id variable, for example:

Lets say for example the database also has the row "product_name".
It is not declared in the URL.
Is it possible to access the value for the product_name row where "id = 1" in a rewrite rule without adding the "product_name" variable to the URL?

For example if the database entry values were:

id = 1
product_name = 'lemon'

Could you create a rewrite rule that would change the following dynamically:


I know the ideal situation would be to just parse "product_name" instead of "id" (I already do this).
I am just curious to if this is actually possible.

Edit: I think people are confused by my question, I am asking if there is a way to do this WITHOUT putting the product_name variable into the source URL.

Edit2: Why do people keep replying with how to do a normal rewrite rule. That isn't my question, I am not asking how you do rewrite rules or asking how they work, I know this already as explained in my original question if you actually bother to read it.

I am asking if it is possible to access a variable from the database that is not included in the URL.
Literally is there anyway at all, even if it is crazy and bad practice to do so. Can you access the row in the database product_name, using just the id row in the URL from the .htaccess file (Not from a PHP file), no is a legitimate answer if that isn't possible. Telling me how to write a rewrite rule with the variable in the URL is not answering my question so stop down voting me just because I wont accept your answer.


While this even might be doable (with prg: External Rewriting Program), really, just don't do it. Write a simple php (or whatever) script.

You have the prg: example here, but read the comments first :)