Get exclusive CAP network offers from top brands

View CAP Offers

Need help with mod-rewrite

[bsa_pro_ad_space id=2]
  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #702089
    Anonymous
    Inactive

    Anybody???

    #702092
    Anonymous
    Inactive

    I don’t have the time to figure this out completely, but I can tell you this: If you want the category name to be in the rewritten URL, then I am pretty sure that the category name also needs to appear in the original URL. At least, that is the only way I would know how to handle it.

    Looking at your rewrite code:

    RewriteEngine on
    RewriteRule ^helpful_links/(.*)/(.*).php /helpful_links.php?pg=$1&cid=$2

    First off, I would delete the forward slash before the word “helpful.” It should look like this:

    RewriteEngine on
    RewriteRule ^helpful_links/(.*)/(.*).php helpful_links.php?pg=$1&cid=$2

    With the above rule, this is what is actually happening….

    The first (.*) is $1. The second (.*) is $2. (I think you know that part already. :) )

    If you want the URL to appear as /helpful_links/2/category-name.php

    –then–

    In the original URL, where you have cid=$2 — the value of $2 needs to be exactly what you want to show up in the rewritten URL. If you have a number here, then the number will be in the URL. If you have a string-of-words-like-this, then that string of words will be in the rewritten URL.

    Examples:

    Original URL: /helpful_links.php?pg=6&cid=7
    Rewritten URL: /helpful_links/6/7.php

    Original URL: /helpful_links.php?pg=2&cid=category-1-here
    Rewritten URL: /helpful_links/2/category-1-here.php

    Original URL: /helpful_links.php?pg=250&cid=wow-look-at-this
    Rewritten URL: /helpful_links/250/wow-look-at-this.php

    Hope that makes some sense. :smoker:

    #702098
    Anonymous
    Inactive

    “In the original URL, where you have cid=$2 — the value of $2 needs to be exactly what you want to show up in the rewritten URL. If you have a number here, then the number will be in the URL. If you have a string-of-words-like-this, then that string of words will be in the rewritten URL”

    This, I understand, but then the script would not know what cid number should be associated with the string of words. And since each cid number is assigned a category, I was hoping to find out if there was a way to write the code to reflect this.

    For example:
    cid 10 = poker
    cid 11 = casino

    The PHP script I am using automatically assigns a cid number to each category I create in the admin panel. It just displays it in the browser as a number instead of the associated name. Perphaps there is a way in the PHP code to manipulate this?

    I can live with displayed results as:
    /helpful_links/2/10.php
    but for the search engines, /helpful_links/2/poker.php would be 10 times better.

    Without the forward slash in front of “helpful_links” how would the script know where to find the file? :tooconfus

    I really do appreciate you taking the time to try to help. thank you!

    #702110
    Anonymous
    Inactive
    ewhitaker wrote:
    Without the forward slash in front of “helpful_links” how would the script know where to find the file?If helpful_links.php is in the main root directory (e.g. yoursite.com/helpful_links.php), then you don’t need the forward slash. (I don’t find it necessary, anyway. I don’t remember if the / messes up the rule or not… you could try it both ways, I guess).

    And since each cid number is assigned a category, I was hoping to find out if there was a way to write the code to reflect this.

    For example:
    cid 10 = poker
    cid 11 = casino

    Yeah, I know what you mean…. Somewhere along the way, the query that calls for the information in your database needs to get the data associated with cid10, cid11, etc… If each cid is assigned to a unique category name, you can make this work by calling for the category name (instead of the cid number) in the query.

    For example, change

    $query = “SELECT * FROM tablename WHERE cid = 10”;

    to

    $query = “SELECT * FROM tablename WHERE categoryname = ‘poker'”;

    (be careful to include the single and double quotes in the right places)

    If the category name is contained in the URL, first you could “GET” the category name and then insert it into the new query, like this:

    $cat_name=$_GET;

    $query = “SELECT * FROM tablename WHERE categoryname = ‘$cat_name'”;

    The URL where it retrieves the cid from would look like this, for example:

    yoursite.com/helpful_links/2/poker.php

    which, from the .htaccess file, would be rewritten to look like this behind the scenes:

    yoursite.com/helpful_links.php?pg=2&cid=poker

    Hopefully this works out for you. Good luck! :D

    #702124
    Anonymous
    Inactive

    Thank you Dave!

    I’m going to give this a try – I’ll let you know if it works. This is my first mysql database, oh boy….

Viewing 5 posts - 1 through 5 (of 5 total)