is this possible?

New to mod_rewrite? This is a good place to start.

is this possible?

Postby lusbal » Wed Oct 21, 2009 8:38 am

i have a old url:
www.bookstore.com/cgi-bin/directory/sto ... nk&sku=P22

and i want to redirect (301) to:

www.bookstore.com/bookdetail/P22/title-of-book

(title-of-book is the name of book, is say, a new variable of my db).
lusbal
 
Posts: 4
Joined: Mon Oct 19, 2009 4:52 am

Postby richardk » Wed Oct 21, 2009 10:13 am

(title-of-book is the name of book, is say, a new variable of my db).

FAQ: How to change a numeric ID into a name/title.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

MYSQL Query in .httaccess

Postby StefanRSA » Fri Oct 30, 2009 4:25 am

I am sorry for replying to this subject without an answer but I think I want to know the same thing?

I want to know if I can make a MySql Query in the .httaccess to populate the mod_rewrite?

I have 10 Main categories with sub-categories and is called in my url at this stage like:
category.php?catid=1&subcatid=9

I want to rewrite the url to display as follow:
categoryname1/subcategoryname9.html

My problem is that although I have only 10 Main categories, the sub categories is dynamic and not a set total...

Can I do a query and how to get the names that will be created with my links so the .httaccess is created dynamically?

.......... Hope I make sense???
StefanRSA
 
Posts: 3
Joined: Fri Oct 30, 2009 1:40 am
Location: South Africa

Postby richardk » Fri Oct 30, 2009 11:20 am

For that you can use a simple RewriteRule
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^[^/]*[^0-9]([0-9]+)/[^/]*[^0-9]([0-9]+)\.html$ /category.php?catid=$1&subcatid=$2 [QSA,L]

You need to edit your script to output the new URLs.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby StefanRSA » Fri Oct 30, 2009 11:56 am

Thanks richardk,

But I want rather the names of each to form part of the url...

Like domain.com/categoryname/subcategoryname.html
The names is in the DB and change dynamically.

Am I wrong in saying that this will improve SEO, thus my reason for rather using cat and subcat names. Therefore I need the .httaccess to be created with a MySql query dynamically.

Can it be done and How?
StefanRSA
 
Posts: 3
Joined: Fri Oct 30, 2009 1:40 am
Location: South Africa

Postby richardk » Mon Nov 02, 2009 10:23 am

Like domain.com/categoryname/subcategoryname.html
The names is in the DB and change dynamically.

Have you read the FAQ i posted earlier in the thread?
Do you have access to the httpd.conf file?
Can you edit the PHP script?

Therefore I need the .httaccess to be created with a MySql query dynamically.

Mod_rewrite can't query MySQL (or other databases) on it's own. You either need a RewriteMap (access to the httpd.conf file required) or to edit the PHP script.

Or, you can have the ID and the name in the link, eg. /categoryname-categoryid/subcategoryname-subcategoryid.html
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^[^/]+-([0-9]+)/[^/]+-([0-9]+)\.html$ /category.php?catid=$1&subcatid=$2 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 7 guests

cron