/    Sign up×
Community /Pin to ProfileBookmark

rewriting urls on the fly

I am working on an ecommerce site. The urls should be seo friendly like

[COLOR=”DarkRed”]http://www.mysite.com/apparel/shirt/shirt-with-duck-print.html[/COLOR]

So i want to design my tabele this way

id, section, category, name

Here
section : apparel
category : shirt
name : Shirt with duck print

When a user clicks the product on the table, url of the new page open for the respective product should be rewrited as above

Here my point is that url rewriting should be dynamic and pieces of the expected url will be read from the table.
I
don’t think that i can solve it simply adding a few lines on .htaccess file. There should be also a php side as i think.

So, how i can resolve this problem of me?

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachNov 05.2008 — that's quite simple. Do it via an htaccess rewrite rule.

It should be something like this.

[code=php]
RewriteRule ^http://www.mysite.com/(.*)/(.*)/(.*).html$ http://www.mysite.com/index.php?section=$1&category=$2&name=$3
[/code]


then in the index.php you get use the $_GET variables to query the database. You just need to replace the '-' in the name with spaces.

hope it helps.
Copy linkTweet thisAlerts:
@mrtbltauthorNov 08.2008 — I didnt understand exactly how to make it

I want to give you a real world example

http://www.rabitto.ro/filter.php?id_section=3&id_cat=5&id_prd=255

Here

id_season=3 means : clothes

id_cat=5 means : baby clothes

id_prd=255 : reindeer dress up

so mylink should be like

http://www.rabitto.ro/clothes/baby-clothes/reindeer-dress-up.html

then how does htaccess know that

id_season=3 means : clothes

id_cat=5 means : baby clothes

id_prd=255 : reindeer dress up

????
Copy linkTweet thisAlerts:
@mrtbltauthorNov 10.2008 — no answer men??????
Copy linkTweet thisAlerts:
@JustinNov 11.2008 — As stephan.gerlach said

Make a .htaccess file in the root of your website. (change mysite.com)

This tells it to match http://www.mysite.com/apparel/shirt/shirt-with-duck-print.html

As http://www.mysite.com/index.php?section=apparel&category=shirt&name=shirt-with-duck-print

[CODE]
RewriteRule ^http://www.mysite.com/(.*)/(.*)/(.*).html$ http://www.mysite.com/index.php?section=$1&category=$2&name=$3
[/CODE]


Then in the php code, it will be passed like this

$_GET['section']

$_
GET['category']

$_GET['name']
Copy linkTweet thisAlerts:
@ayveghNov 11.2008 — ... and then, in your PHP script, have it look up the ID value for those text values (escaping properly, obviously), and then you'll be right where you want.
Copy linkTweet thisAlerts:
@mrtbltauthorNov 12.2008 — here is how i modified my .htaccess file


[code=php]

RewriteEngine On

RewriteRule ^http://www.neykids.com/(.*)/(.*)/(.*).html$ http://www.neykids.com/products.php?section=$1&category=$2&name=$3
[/code]


and one of my link from the menu is :

http://www.neykids.com/imbracaminte/

this link means the following

[code=php]
http://www.neykids.com/products.php?section=imbracaminte
[/code]


right?

But it doesnt work!!!!!
Copy linkTweet thisAlerts:
@JustinNov 12.2008 — here is how i modified my .htaccess file

http://www.neykids.com/imbracaminte/

this link means the following

[code=php]
http://www.neykids.com/products.php?section=imbracaminte
[/code]

[/QUOTE]


IT doesn't work because the example you ask for had a .html So it is trying to match a .html

You also said you wanted /***/***/***.html. That is what it is trying to match... you didn't say anything about wanting it to be partsial... the example you were given will only match urls following the entire example. so it is looking for the entire url not just parts of it.
Copy linkTweet thisAlerts:
@mrtbltauthorNov 12.2008 — here is what i have in .htaccess

[code=php]
RewriteEngine On
RewriteRule ^http://www.neykids.com/(.*)/(.*)/(.*).html$ http://www.neykids.com/products.php?section=$1&category=$2&name=$3[/code]


then lets say that my link is

http://www.neykids.com/apparel/234234/sdfsdf.html

actually it is same with the following :

http://www.neykids.com/products.php?section=apparel&category=234234&name=sdfsdf

right?

Shouldn't both links return products.php with some plus conditions?


but the first one doesnt return products.php file
Copy linkTweet thisAlerts:
@JustinNov 12.2008 — Its giving me a 404, where did you put your .htaccess file? Does your server support .htaccess files?
×

Success!

Help @mrtblt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...