Jump to content

Rewriting dynamic url to static


BuildMyWeb

Recommended Posts

i know the answer has to be here, or elsewhere on the web, but ive searched both for the last hour and im more confused than when i started. 

 

i read this as well and it cleared some things up relating to other issues but not this issue: http://corz.org/serv/tricks/htaccess2.php

 

anywho, my problem is i have a php site where we pass GET values in the URL.  we dont want users to see the ugly URLs however.  so for instance, this is the current URL:

"http://mysite.com/details.php?prod=36271"

 

and we want to write a line it htaccess that rewrites the URL to:

"http://mysite.com/a-nicer-url"

 

is the above even possible?  this is my best attempt thus far:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^details\.php\?prod=36271$
RewriteRule /a-nicer-url/%1 [L,R]
Link to comment
Share on other sites

It's certainly possible but we need to know more.

 

What kind of URLs do you want? Creating a new RewriteRule for everything is crazy (unless there's a very small number of them and they won't change) so you need something more dynamic than "a-nicer-url maps to product 36271".

 

To do that there are two basic options:

1. The new URLs need to have the same information present in the old URLs but in a different form, like "/product/36271", with even more information than that if you want.

2. You alter the details.php to accept a different set of information that you do put in the new URL. Like if product #36271 is called "a-nicer-url" then you can do that, but you have to edit the script to know to look for the name instead of the ID.

 

Also consider a URL that isn't at the top level of the website, like /product/36271 or /product/a-nicer-url. Cleaner that way.

Link to comment
Share on other sites

there is an SEO party involved that wants specific replacements for these dynamic URLs and the replacements are not necessarily of any pattern that i can write a regexpression for.  some have the id# in the new URL (in the above case "36271") and others dont.  i also didnt want to track down every link on the site that uses the old URL and replace it with a static one.  ie. find all instances of "/details.php?prod=36271" and in the HTML replace with "/a-nicer-url"

 

there is only a product line of about 40 items so crazy as it seemed, i was considering writing up to 40 individual rewrites

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.