Newbie Question on Mod ReWrite

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

Newbie Question on Mod ReWrite

Postby freerap » Sun Jun 13, 2004 12:07 pm

I have trawled the net trying to figure this out. My new site has 3 basic pages using the following links. (Please bear in mind I new no PHP a week ago)

http://www.mysite.com/browse_products.p ... nufacturer

http://www.mysite.com/browse_catagory.p ... ame=basque.

http://www.mysite.com/product_detail.ph ... rgentovivo


Please can someone tell me how to improve this with mod rewrite? I assume the best way would be to have the actuall product name in the this is the name.html format but I have no idea how to do this.

Any help would be great. Thanks.
freerap
 

Re: Newbie Question on Mod ReWrite

Postby seomike » Mon Jun 14, 2004 4:26 am



First thing you need to do is change the coding in your
browse_products.php
browse_category.php
product_detail.php

Right now the links are out putting those urls up above. you need to change them so they out put as if they were .html instead of the query string.

You said that a .html format would be best. So if you take the strings above in order, you should change them to out put this:

Code: Select all
http://www.mysite.com/manufacturer.html

http://www.mysite.com/bras-asque.html

http://www.mysite.com/195721722-Argentovivo.html


you would put this in the .htaccess to get the mod rewrite to process those pages.

Code: Select all
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/[a-zA-Z]+[^-]\.html$
RewriteRule ^([a-zA-Z]+)\.html$ ^/browse_products.php?product_manufacturer=$1 [L]

RewriteCond %{REQUEST_URI} ^/[a-zA-Z]+-[a-zA-Z]+\.html$
RewriteRule ^([a-zA-Z]+)-([a-zA-Z]+)\.html$ ^/browse_catagory.php?products_catagory=$1&products_name=$2  [L]

RewriteCond %{REQUEST_URI} ^/[0-9]+-[a-zA-Z]+\.html$
RewriteRule ^([0-9]+)-([a-zA-Z]+)\.html ^/product_detail.php?product_id=$1&product_manufacturer=$2 [L]


hope this helps
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Guest » Mon Jun 14, 2004 10:53 am

Many thanks for trying to help but I'm afraid it doesn't seem to work :-(

I have pasted the code into my htaccess and it makes no difference at all.

Any ideas ??
Guest
 

Postby seomike » Mon Jun 14, 2004 11:56 am

have you changed the code in your php files to out put
this
http://www.mysite.com/manufacturer.html
instead of this:
http://www.mysite.com/browse_products.p ... nufacturer
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Guest » Tue Jun 15, 2004 5:17 am

How do I do that? I'm afraid I'm very new to php, like i knew none 2 weeks ago :-(
Guest
 

Postby seomike » Tue Jun 15, 2004 9:20 am

you open the php file.

find anywhere it says <a href=......</a>

and modify it.

If you want you can put the <a href info in here and I'll modify it for you. That way you can see how it's done and then you can do it throughout the site.
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Guest » Wed Jun 16, 2004 2:56 am

Thanks Mike. I understand how to modify the links, just not what to change them to? Here is one of my static links.........

<a href="browse_catagory.php?products_catagory=bras&products_name=basque" class="menu">Basque</a>

These are dynamic links.....

<a href="browse_products.php?product_manufacturer=<?php echo $row_rs_manufacturer['product_manufacturer']; ?>" class="menu"><?php echo $row_rs_manufacturer['product_manufacturer']; ?></a>

Many thanks for your help. I'm sure I shall get there in the end.
Guest
 

Postby seomike » Wed Jun 16, 2004 8:20 am

Change this
<a href="browse_products.php?product_manufacturer=<?php echo $row_rs_manufacturer['product_manufacturer']; ?>" class="menu"><?php echo $row_rs_manufacturer['product_manufacturer']; ?></a>

to this

<a href="<?php echo $row_rs_manufacturer['product_manufacturer']; ?>.html" class="menu"><?php echo $row_rs_manufacturer['product_manufacturer']; ?></a>

it will out put this yourdomain.com/manufacturer.html

back up the php file just incase you need to reference it again before you make these changes.


this is only 1 out of the 3 keep'em coming. :) :) I'll help you change the rest!
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby Guest » Wed Jun 16, 2004 10:26 am

OK Mike, I have tried that on my test server and it does as you say output the link as html, however it doesn't work and I get a 404 error.

Does the .htaccess as mentioned above need to be in place to? I'm also confused how the link you have posted calls the browse_products.php file ?? It doesn't appear to tell it what page to go to?

Could this be due to the test setup as I'm using foxserve on a win2k box?

I haven't had time to try it on a really live server yet but I'll give that a go tommorow.

Thansk for you help.
Guest
 

Postby Guest » Wed Jun 16, 2004 10:31 am

O just tried this instead


<a href="browse_products.php?product_manufacturer=<?php echo $row_rs_manufacturer['product_manufacturer']; ?>.html" class="menu"><?php echo $row_rs_manufacturer['product_manufacturer']; ?></a>

and that at least goes to the correct page, but the recieving page doesn't get the variable it is expecting and doesn't proccess the data?
Guest
 

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 6 guests

cron