SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod Rewrite Dynamic to Static Help

    I have a site that generates dynamic links. I would like them to appear static for SEO purposes.

    If I have a link:
    ->http://www.mydomain.com/template.php?sn=Name1-Name2-Name3-Screen-Saver&id=142

    and I want it to appear as:
    ->http://www.mydomain.com/Name1-Name2-Name3-Screen-Saver.html

    what code would I need to place in my .htaccess file? I've been researching this for hours and still haven't figured it out.

    On a side note, on a few rare occasions the $sn variable may contain either an ampersand sign "&" and/or a period ".".

    For example:
    ->http://www.mydomain.com/template.php?sn=Sky-&-Clouds-Screen-Saver&id=142

    or

    ->http://www.mydomain.com/template.php?sn=Sky-Vol.1-Screen-Saver&id=142

    Will that cause me any problems when doing the mod_rewrite?

    Thanks much in advance!

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    WPPJ,

    It would be a piece of cake to take the second URL you gave and build the first from it ***IF*** there was a place to get the id's value. Since there does not appear to be, you're SOL!

    Regex? Use character definitions with ranges, i.e., [-a-zA-Z0-9&.]+ where the first - is a hyphen character (the others are part of the range definitions) and the & should match the hex encoded value for the ampersand (you CANNOT include that in your query string as that is a reserved character - just like the ?) and the dot character.

    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

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be a piece of cake to take the second URL you gave and build the first from it ***IF*** there was a place to get the id's value. Since there does not appear to be, you're SOL!
    Thanks for the reply, but I don't fully follow you. The first URL I provided is what I currently have - the dynamic one with the sn and id variables. The second is what I want to create ("spoof") - the static one. So wouldn't I be "building" the second URL from the first, not the other way around?

    Or are you saying that because I have two variables in the first URL I have to use both of the values of those variables in the second URL and not just value of the sn variable?

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    WPPJ,

    No, as webmaster, you build/use the second but Apache needs to serve the first so the regex must match the second and create the first from it. As to the second variable, if that's a constant, the problem is solved. If not, "you can't get there from here" (what you provided).

    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

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dklynn. No wonder I was having so much trouble - I was trying to work the whole process backwards. I have everything working just as I wanted now.

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    WPPJ,

    Excellent! There is a "fog" over this mod_rewrite magic but, once the fog is parted, it's a very useful tool! Enjoy!

    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

  7. #7
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I guess I'm still in a fog, as I had to make a change and am having trouble.

    I am now trying to convert a static URL in this format:

    ->http://www.sexy-screen-savers.com/14...een-Saver.html

    to this:

    ->http://www.sexy-screen-savers.com/te...2&sn=Cool-Cats

    I have this in my .htaccess file, which is incorrect:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteRule ^(.*)/(.*)-Screen-Saver.html template.php?id=$1&sn=$2

    What do I need to change? Thanks!

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    WPPJ,

    Please take a look at my rant in this thread and consider yourself one of those who do NOT understand regex.

    Quote Originally Posted by WPPJ
    http://www.sexy-screen-savers.com/142/Cool-Cats-Screen-Saver.html

    to this:

    http://www.sexy-screen-savers.com/template.php?id=142&sn=Cool-Cats
    Code:
    # DocumentRoot's .htaccess
    RewriteEngine on 
    RewriteRule ^/?([0-9]+)/([-a-zA-Z]+)-Screen-Saver\.html template.php?id=$1&sn=$2 [L]
    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
  •