Mobile app version of vmapp.org
Login or Join
Nimeshi995

: Possible to drop the original query parameters entirely in a rewritten URL? Original URL looks something like domain.com/filename.php?id1=333&id2=444. Desired rewritten URL is something like domain.com/my-rewritten-url.

@Nimeshi995

Posted in: #Htaccess #Permalinks #UrlRewriting

Original URL looks something like domain.com/filename.php?id1=333&id2=444.

Desired rewritten URL is something like domain.com/my-rewritten-url.

I can imagine creating a lookup table with columns for the ids and a column for the rewrite string, but is this realistic/practical?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Nimeshi995

1 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

This is very possible to implement. I have implemented it myself. It requires more than a rewrite rule though. It requires you to change the code that runs your web application. Here is how I have made it work:


A request comes in for /my-rewritten-url
A rewrite rule forwards it to `/filename.php?path=my-rewritten-url
The PHP script does a database query to get the parameter string (id1=333&id2=444) and the file name that should handle the request (show-this-page-type.php)
It parses that parameter string and puts the values into the parameter map
It dispatches the request to show-this-page-type.php


The downsides are:


It adds an extra database query (caching can help)
It requires that your website be powered by a single script that may have to dispatch requests out to other scripts
It breaks analytics that are rely on the existence of parameters in the URLs or the name of the script. (It is much harder to determine page type, for example.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme