- This topic is empty.
-
AuthorPosts
-
August 15, 2006 at 4:38 am #702089
Anonymous
InactiveAnybody???
August 15, 2006 at 5:19 am #702092Anonymous
InactiveI 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=$2First 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=$2With 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.phpOriginal URL: /helpful_links.php?pg=2&cid=category-1-here
Rewritten URL: /helpful_links/2/category-1-here.phpOriginal URL: /helpful_links.php?pg=250&cid=wow-look-at-this
Rewritten URL: /helpful_links/250/wow-look-at-this.phpHope that makes some sense. :smoker:
August 15, 2006 at 7:46 am #702098Anonymous
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 = casinoThe 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!
August 15, 2006 at 12:05 pm #702110Anonymous
Inactiveewhitaker 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 = casinoYeah, 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!
August 15, 2006 at 3:12 pm #702124Anonymous
InactiveThank 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….
-
AuthorPosts