SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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!
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    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.
    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.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •