PDA

View Full Version : Mod rewrite-is it really necessary?


catchmeifucan
03-03-2005, 01:09 PM
Hi,

other than make your url keyword rich, do you really think Mod rewrite is necessary?

Google, MSN, and Yahoo both index dynamic urls up to three parameters, as far as I site is concerned.

I have a mod rewritten site. Google index almost all the dynamic urls, but only part of the the rewritten urls.

Do you really thing mod rewrite is necessary? does it help you ranking?

lots0
03-03-2005, 01:39 PM
Take a look at the first page in google for any reasonably compeditive keyword(s) , how many dynamic urls do you see?

seomike
03-03-2005, 02:12 PM
I've seen the before and after data on our cutomers and its like night and day. The key is IF you do it right. I had to botch it on a few of our own domains before I figured out there is a right way to mod and a wrong way.

1. Keep directories 1-2 level deep.
2. Crosslinking is the key to power.
3. Use the mod to create dynamic 301's from old to new urls.

That just gives you the power to have a fully indexable site. Then it just comes down to how good of an optimizer you are. If the structure is sound then the sky is the limit and it's up to you.

catchmeifucan
03-03-2005, 04:06 PM
how do you match thousands of ids one by one?

product_info.php?product_id=1 301 to /product-1.html
.
.
.
produc_info.php?product_id=5000 301 to /product-5000.html

how do you do it dynamically?

grnidone
03-03-2005, 04:09 PM
Don't do Mod_rewrite just for google. Do it for your consumers.

It is a whole lot easier for a user to remember (and cleaner in the bookmarks)

www.site.com/product/product-name

than it is for a user to remember

www.site.com?product=blat&yadda&12467683

Honestly. I use mod rewrite for usability purposes. The fact that google likes it is icing on the cake.

grnidone
03-03-2005, 04:16 PM
how do you match thousands of ids one by one?

product_info.php?product_id=1 301 to /product-1.html
.
.
.
produc_info.php?product_id=5000 301 to /product-5000.html

how do you do it dynamically?


The answer to that my friend is in regex, also known as regular expressions. You match the pattern of the dynamically hard to read url to a new pattern.

For example:

Using regex, you say "Find this pattern and when you do, make that pattern look like this one."

So you say (in regex)

"Look for this pattern": product_info.php?product_id=*
and when you find it, transform that pattern to this pattern:
product-*.html

My regex is rusty, so I can't just tell you the exact pattern to do it, but that is the basic idea. At least you know the right things to say to the techs if you are having someone else do it.

grnidone
03-03-2005, 04:18 PM
Ooh...just found this post that actually shows you a .htaccess file using mod_rewrite:

http://forums.searchenginewatch.com/showthread.php?p=37293

seomike
03-03-2005, 06:24 PM
how do you match thousands of ids one by one?

product_info.php?product_id=1 301 to /product-1.html
.
.
.
produc_info.php?product_id=5000 301 to /product-5000.html

how do you do it dynamically?

piece of cake with 1 rule

RewriteCond %{QUERY_STRING} ^product_id=([^&]+)$
RewriteRule ^$ /product-%1.html [R=301,L]

That will get every product_id= if you have other dynamic urls you can create rules for those too.

catchmeifucan
03-04-2005, 01:21 PM
Thanks, everybody!

I've studied it for half a day yesterday and I guess I got the point. half a year ago I outsourced it to a programer. what he did was set up a customized 404.php page and feed all the dynamic URLs there. Is there any advantage doing that? Is that more flexible in terms of what the urls you want?

For example,
my category url was /index.php?cpath=xxxx. with .htacess rewrite, it seems it would be difficult to rewrite it to /actual-category-name/

Right?

seomike
03-04-2005, 02:04 PM
If the dynamic url was
/index.php?cpath=actual-category-name
then the mod rewrite could do it easily. Could you post the real dynamic url so I can see it :)

grnidone
03-04-2005, 02:19 PM
Catchme:

Mod_rewrite is one of the sexiest pieces of Apache. It is well worth studying about and learning what all it can do. It makes you life easy.

catchmeifucan
03-04-2005, 05:43 PM
If the dynamic url was
/index.php?cpath=actual-category-name
then the mod rewrite could do it easily. Could you post the real dynamic url so I can see it :)
www.samszone.com/index.php?cPath=118_122
www.samszone.com/product_info. php?products_id=539

seomike
03-04-2005, 07:18 PM
Yeah there's not much to work with. But there is a way to get around it :)

RewriteCond %{QUERY_STRING} ^cPath=([^/]+)$
RewriteRule ^$ /301-director.php?cPath=%1 [L]


RewriteCond %{QUERY_STRING} ^products_id=([^/]+)$
RewriteRule ^$ /301-director.php?products_id=%1 [L]


php page code 301-director.php

This will get you by if your mod is just standard /products-xxx or /cat-xxx for all items.


<?
// get the variable used to form the new urls from db or error 404
if(isset($cPath)){
$string_tail = "cat-".$cPath."/"; // change to fit your urls ending
$redirect = 1;
}else if(isset($products_id)){
$string_tail = "product-".$products_id.".html"; // change to fit your urls ending
$redirect = 1;
}else{
header("HTTP/1.1 404 Not Found");
header("Location: http://www.yourdomain.com/");
}//if(isset($cPath)){

// 301 redirect to the new mod rewritten url or error 404
if($redirect == 1){
$new_url = $string_tail;
header("HTTP/1.1 301 Moved Permanently");
header("Location: $new_url");
}else{
header("HTTP/1.1 404 Not Found");
header("Location: http://www.yourdomain.com/");
}//if($redirect == 1){

?>

Here I'm making up table and column names. Basically all you do is change the tables and columns to match your sites db structure. Hopefully the mod

<?
// db connection
include("db_connector.php");

// function to create a mod url
function mod_rul($url){
$url = strtolower($url);
$url = str_replace(" ","-",$url);
return $url;
}//function mod_rul($url){

// get the variable used to form the new urls from db or error 404
if(isset($cPath)){
$sql = mysql_query("SELECT cat_name FROM category WHERE cPath = '$cPath'");
$string_tail = "-".$cPath."/"; // change to fit your urls ending
}else if(isset($products_id)){
$sql = mysql_query("SELECT products_name FROM products WHERE products_id = '$products_id'");
$string_tail = "-".$products_id.".html"; // change to fit your urls ending
}else{
header("HTTP/1.1 404 Not Found");
header("Location: http://www.yourdomain.com/");
}//if(isset($cPath)){

// 301 redirect to the new mod rewritten url or error 404
if($rw = mysql_fetch_array($sql, MYSQL_NUM)){
$new_url = mod_url($rw[0]);
$new_url .= $string_tail;
header("HTTP/1.1 301 Moved Permanently");
header("Location: $new_url");
}else{
header("HTTP/1.1 404 Not Found");
header("Location: http://www.yourdomain.com/");
}//if($rw = mysql_fetch_array($sql)){

?>

The entire point of this is to make the ?cPath=xxx_xx mod rewrite to this 301-directory.php which puts together the correct url and triggers the 301.
Since we are using the [L] flag instead of [R] the search engines just think ?cPath=xxx_xx is doing the 301 to the new url. It's pretty tricky but NOT spam tricky :) I use it on a few sites and it work like a charm.

You'll definitely have to tweek it to fit but this should be enough to get you started. :D

catchmeifucan
03-06-2005, 04:02 PM
wow! thanks a lot Mike.

but I have a legacy system that a coder did it for me half a year ago. He set up a custom 404.php and feed all the product urls there and rewrite it.

here is the link to his source code.

http://forums.searchenginewatch.com/showpost.php?p=35740&postcount=17

I guess I have to look into it more carefully to see if I need everything redone or have him modify his code to get this work.

is there a quite code for turning this

http://www.samszone.com/coupons.php?c_id=1&c_name=PC%20Hardware

into

http://www.samszone.com/coupons/pc-hardware-coupons.html?

Thanks

catchmeifucan
03-06-2005, 04:09 PM
how come it cut my url short?

Mike, can you help me with a quick code for turning

/coupons.php?c_id=1&c_name=PC%20Hardware

to

/coupons/pc-hardware-coupons.html

catchmeifucan
03-09-2005, 02:09 PM
Hi, Mike and Mike

it seems that Google is not fully indexing my rewritten urls

a search for site:www.samszone.com inurl:scooters only returns 116 pages, where as I have at least several hundred of products. Do you have any suggestions how to get them indexed?

How do you guys deal with your more listing pages such as

http://www.samszone.com/scooters/electric-scooters/?sort=2a&page=2

Google had a cache for such page half a year ago, it seems it is not indexing this page and the subsequent pages now.(MSN did index it)

if I rewrite it to

http://www.samszone.com/scooters/electric-scooters/2a-2/

would it help?

Another question is regarding the directories. I think you suggested no deeper than 2-3 directories.

right now the rewrite add all parent directories which makes a long url such as

http://www.samszone.com/scooters/scooter-parts/electric-scooter-parts/

It is indexed by Google, MSN, and Yahoo. Should I consider changing it to

http://www.samszone.com/electric-scooter-parts/

for product urls, righ now url structure is

http://www.samszone.com/scooters/scooter-parts/electric-scooter-parts/125x25-tire.html

should I just use

http://www.samszone.com/125x25-tire.html

Thanks for suggestions