Jump to content


Photo

Rewriting dynamic url to static


  • Please log in to reply
5 replies to this topic

#1 BuildMyWeb

BuildMyWeb

    Advanced Member

  • Members
  • PipPipPip
  • 111 posts
  • LocationNY

Posted 10 September 2013 - 02:34 PM

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...s/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/de...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]

Freelance Web Developer | Web Hosting | PHP Applications
Web Development, Hosting, Graphic Design, SEO


#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,150 posts
  • LocationWA

Posted 10 September 2013 - 02:52 PM

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.

#3 BuildMyWeb

BuildMyWeb

    Advanced Member

  • Members
  • PipPipPip
  • 111 posts
  • LocationNY

Posted 10 September 2013 - 04:21 PM

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


Freelance Web Developer | Web Hosting | PHP Applications
Web Development, Hosting, Graphic Design, SEO


#4 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,714 posts
  • LocationBonita, FL

Posted 11 September 2013 - 12:31 AM

If you have a bunch of arbitrary redirections with no real pattern, you may just need to generate a bunch of rewrite entries for each url (or use RewriteMap)
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#5 BuildMyWeb

BuildMyWeb

    Advanced Member

  • Members
  • PipPipPip
  • 111 posts
  • LocationNY

Posted 12 September 2013 - 04:55 PM

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.


Freelance Web Developer | Web Hosting | PHP Applications
Web Development, Hosting, Graphic Design, SEO


#6 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,664 posts
  • LocationMississauga, Canada

Posted 15 September 2013 - 07:29 PM

You should know, that you need to have an access to apache .conf file to use the RewriteMap directive. I'm find it for very useful solution in your case.

 

 

 

Context: server config, virtual host






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com