The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help writing a mod_rewrite Rule

Discussion in 'General Discussion' started by noimad1, Aug 30, 2008.

  1. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    I'm such a noob when it comes to mod_rewrite rules. I've been trying to get this rule written for a few hours now using different tutorials, but I'm not having any luck.

    Here is the URL that is already programmed into the customers site:

    http://www.hissite.com/view_product~product~MagM88.php

    And I need that to actually pull up this URL:

    http://www.hissite.com/view_product.php?product=MagA1


    I guess his previous host used some windows based program to accomplish this rewrite. But I'm trying to get it to work on mod_rewrite with no luck.

    If any rewrite experts are out there and could give me a quick rule that would be great.
     
  2. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    Sorry to be a pest. Can anyone help out with this one?
     
  3. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,474
    Likes Received:
    202
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    If it was me, I'd suggest they update the links to those images down the left side of the page. (I was able to find this site or a site with identical problem, via google)

    If you visit: ht tp://hissite.com/view_product.php?product=MagA1

    And mouse over those images to the left, not all even use that sort of link. Some do, some don't. Why not just update the ones that do so they work properly instead of this fancy way he's doing it now?

    Does one style work better than the other for search engines to find what he's selling? I'm not sure there. My guess would be there is a difference.

    I did find something else on google from 2006 and this same website was wanting to change these links in this fashion you mention, and the topic mentioned a cubecart mod that (I guess) was able to do this.

    Might want to look around the cube cart forums and see what you can find there.

    Sorry can't help more than that.
     
  4. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    The problem currently is that this customers URL's have been out there for years, and the search engines already have them indexed with the fancy format. Now that he has moved the hosting to me I was hoping to write a mod_rewrite rule to save those rankings for him until he get's re-crawled/ranked.
     
  5. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,474
    Likes Received:
    202
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    I'd check the CC forums then. By that link on google it appears it was the site owner who posted and was told there were two mods that could do this. (IIRC) He doesn't recall adding something to his own site?
     
  6. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    I'll try to search the forums again. The customer did have this working on his other host as I mentioned. It was not done through cube cart though. He used some windows-based program called Link Freeze or something like that, that changed all of his links to these fancy links. I really don't know how that program works exactly.

    I'm sure a mod_rewrite could work here? I just am not proficient enough with it to get it to work. I'm sure someone out there is though...
     
  7. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,474
    Likes Received:
    202
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
  8. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16

    Thank you very much for the information. However, I know the tilde isn't worth using. In fact, the customers site is not going to use these formats for the URL's any longer. I still need to update the links for the pictures on the left to the correct URL's.

    The problem is again that the search engines have the old "Fancy" URL's crawled and indexed. So the customer doesn't want to lose that traffic. So that's why I'm trying to write a mod_rewrite rule to forward the URLs to the correct place.

    The cube-cart link you sent does have info about some mod_rewrite rules, but those are specifically for the "search engine friendly" URL feature already built into cube cart, so it doesn't work for this instance.

    This customer didn't use that. They used some Link-Freeze Program to create these custom, fancy URL's.

    I'm just trying to see if it is possible at all to do a mod_rewrite rule for this kind of URL:

    http://www.hissite.com/view_product~product~MagM88.php

    to point to:

    http://www.hissite.com/view_product.php?product=MagA1

    so he doesn't lose any of his existing traffic from the search engines.
     
  9. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,474
    Likes Received:
    202
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Well my thoughts were from those few links that you could probably put together what you wanted from them. I didn't bother trying myself though.

    If he's not going to use the tilde any longer why not set up the search engine friendly URLs and a new google map / site map and get reindexed?

    Dunno, as I said, wish I could help more.
     
  10. noimad1

    noimad1 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    627
    Likes Received:
    0
    Trophy Points:
    16
    Ok, well I came up with a fix. Not exactly what I wanted to do, but it works exactly the way I need it.

    First thing I did was wrote this into .htaccess:

    RedirectMatch 301 ^/view_product~([^.]+)(.*)$ http://hissite.com/view_product.php?product=$1

    Which takes the url and rewrites it as:

    http://hissite.com/view_product.php?product=product~MG45

    I then went into his view-prodcut.php file and wrote a simple string replace:

    $product = str_replace("product~", "", $product);


    And tada...things are working.....so forget the mod_rewrite (which would have probably been the better way to do it).
     
Loading...

Share This Page