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
https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/
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.

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

i didnt want to track down every link on the site that uses the old URL and replace it with a static one.  that was my objective.  but it sounds like from what you guys are advising, i will have to do that in this scenario. 

 

thanks for the advice.  i appreciate it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.