Grab variables out of URL then rewrite the URL to remove variables?

Once a user clicks on this URL:

oil-testimonials.com/newVersion/essential-oils.php?tID=3177$referralID=12345

Is it possible to use mod_rewrite to make the URL look like this?

oil-testimonials.com/newVersion/3177/lavender-for-a-serious-burn

My page, essential-oils.php requires a tID to know which testimonial to show, but it can also accept a referalID or a searchID if one is present. I’m trying to figure out how to change the URL so that when the page is done loading, a consistent URL is shown in the address bar. This will help increase SEO link juice as well as allow Facebook like counts to increase properly. Currently the likes don’t always increase because the page is seen as different URLs when a referralID or searchID are present. Does this make sense?

Thanks!

No its not possible to use mod_rewrite in that regard. Adding textual slugs from a database is not something you do with mod_rewrite. Now if you drop to the stupid textual slug (lavender-for-a-serious-burn) then sure it is possible.

l_e,

Au contraire! Where do you think mod_rewrite would find the referralID=12345 (and why in the world would you replace the query string’s &'s with $'s?).

both,

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

bb,

oil-testimonials.com/newVersion/essential-oils.php?tID=3177$referralID=12345

Is it possible to use mod_rewrite to make the URL look like this?

oil-testimonials.com/newVersion/3177/lavender-for-a-serious-burn

Are you serious? I thought the question was to go in the other direction (possible EXCEPT for the $referralID=12345). When working with SEO redirections, it’s the webmaster’s task to define the format for the links to be seen then create the mod_rewrite code to convert that to what Apache needs to serve the required page. Your question is “how can I change the visible URI to something which cannot be served?” If you read my tutorial, you’ll know that it can be done but not in the manner you suggest and it’s a burden on the server to perform loopy redirects without a valid reason (like 301 redirecting old format links to new).

Regards,

DK

I know how to use mod_rewrite…maybe you know the secret of adding data from the database like a text slug using mod_rewrite? As per what the OP wants to-do is change from one URL to one with a text slug (lavender-for-a-serious-burn) which is not in the first URL. Doing so would require A) the values are hardcoded, or B) some interaction with a database.

Having the text slug is pointless anyways.

l_e,

I can’t speak to the OP’s real intentions because it just doesn’t make sense (to me). I suspect that you’re correct as to the intent and know that your suggestions are the most likely candidates for “junior webmasters.” There are, of course, also the options of using a RewriteMap or creating a “handler file” for the redirections which would certainly either be hardcoded or have access to a database - just as you had stated.

I have to disagree with your last sentence, though, as I have a client (who is not a “slug”) but did want his titles used in the URIs in lieu of the numeric keys. This was accomplished pretty easily using mod_rewrite on the links which are the page titles - see http://wilderness-wally.com/ Personally, I love that treatment and believe it’s far superior to article.php?id=123 or even article/123. All it takes is creating the link properly from the database and using mod_rewrite to redirect to the article writing script with the title (which is an unique key, i.e., no duplicate titles and enforced by the database structure). Knowing what characters are allowed in a URI (http://www.ietf.org/rfc/rfc2396.txt) is also helpful.

Regards,

DK