PDA

View Full Version : any one used mod_rewrite?


edbr
04-01-2008, 01:43 AM
I changed a site recently to php and more info database fed. i immediately dropped visitors to 20 % and dumbly thinking things would settle down lost google pr from 5 - 4. not a happy camper!
i have been looking at mod rewrite and have added a htaccess file so now
http://www.concord-bali-villas.com/villa.php?villa=jajaliluna

is now accessed by
http://www.concord-bali-villas.com/jajaliluna.html

my question is, before i change the links, is this going to make a big difference re search engine indexing in any ones experience or not.

domedia
04-01-2008, 12:50 PM
Hopefully someone can give you some hints. I just wanted to chime in and say that PR is not an end goal so don't look at it. It is also a product of your incoming links, so has nothing to do with your site structure.

edbr
04-02-2008, 01:01 AM
thanks dom. i get that but it is to me an indicator. the index pages has dropped by 20 % (????) and I read that this could be a product of .php?###.
whatever i will probably do this but am hoping for some comment by someone with experience before i commit to it, incoming links hasn't changed as the links are all to the index page although i may change this also to appear as html rather than php , cant see any real reason why this would matter.

domedia
04-02-2008, 01:42 AM
Make sure you focus on the end result, either amount of visitors or amount of sales and try to determine where in this process you might be able to improve.

As a general guideline, search engine friendly urls are preferred. They are easy for search engines to spider, and easier for humans as well to type :)

Whenever you change site structure it's important to redirect old pages to new ones using a 301 permanent redirect. If not all your old incoming links will go to pages not there.

Let me know if I can help you with this more, can't promise I can respond fast, but I'll do my best :)

edbr
04-02-2008, 01:53 AM
Whenever you change site structure it's important to redirect old pages to new ones using a 301 permanent redirect. If not all your old incoming links will go to pages not there.
good point that wish i had thought of that. I am pretty committed to making the changes just being cautious / cowardly, take your pick really.
thanks again dom

domedia
04-02-2008, 02:03 AM
Here's what you do now: do a search on Google for all pages in your domain, it's under advanced search. If any of the pages in hteir index are still going to old pages, make a .htaccess 301 redirect.

Also look at your site statistics and see if you get traffic to pages that you currently don't have anymore.

edbr
04-09-2008, 09:44 AM
ok i did the deed and all the links are ok,
my question is will
blah.com/page.php?villa=coco,
which is now blah.com/coco.html
be seen as a duplicate page or will the mod rewrite be enough??

pete
04-09-2008, 10:15 AM
I recently did similar on a big site and used redirects, google seemed to handle the transition well with old and new entries showing at the same time, several months later the new urls have replaced the old ones.

If it were me though I would create the rewrite rule on villa_detail.php and on page villa.php I would have a list of all villas with a link to the new detail page which would be /villa_name.html

That way when google and users still go to villa.php?name=value they see a new page with all villas listed. Still add the redirects though as domedia explained.

You must also be checking for a valid record because anyone can insert any copy into your page and send it to someone to view. Click this link:
http://www.concord-bali-villas.com/I%20can%20put%20whatever%20i%20want%20in%20your%20 page.html

If I were an idiot I could put in obscene words and submit that link to google so people visit your page and see f*** s*** or whatever which is not ideal.

You must remember even urls are user input and should be checked, sanitized and filtered. If a villa isn't valid, eg http://www.concord-bali-villas.com/novilla.html then don't show me that page, display a message like 'The villa you have chosen is not currently listed'.

edbr
04-10-2008, 12:55 AM
You must also be checking for a valid record because
aargh !! thanks for that sure wasnt thinking of that!

and the rest .

edbr
04-10-2008, 05:50 AM
i closed those doors in a panic!! not correctly yet but i will look at the if statements later. once again thanks for uncovering my less than bright mistake!

pete
04-10-2008, 07:58 AM
Just ensure you have a valid query so something like



$result = mysql_query(
sprintf("
SELECT
villa,
image,
description
FROM
villa
WHERE
name = '%s'
LIMIT 1
",
mysql_real_escape_string($_GET['villa'])
)
);
if($result){
if(mysql_num_rows($result)==1){
$row = mysql_fetch_object($result);
echo $row->villa;
} else {
header("Location:http://www.site.com/novilla.php");
exit();
}
} else {
exit("Invalid Villa - stop messing with the url!");
}
One common method is to use ids rather than urls so that you are looking for the $_GET['id'], so your url would consist of site.com/23.villa_name_here.php then in your sql you can simply check for a valid integer using if(isset($_GET['id']) && ctype_digit($_GET['id'])){ ....

Where possible use integers because it is safer and more straight forward than anything else. In your mod_rewrite rules, make sure that they aren't too slack like (*.) as that can interfere with other pages. Another useful trick with mod_rewrite is to use a virtual directory name so www/villa.php is rewritten as www/villas/villa_name.php .

edbr
04-10-2008, 08:37 AM
right, i will look at that soon as.
Another useful trick with mod_rewrite is to use a virtual directory name so www/villa.php is rewritten as www/villas/villa_name.php .
didnt understand why that is more secure, im very new to this as you can tell

for now i used an if statement that matches against names in the databasei f not or if empty echos an alert, is this not enough do you think?

pete
04-10-2008, 09:01 AM
I wasn't very clear there, I meant rewrite www/villa.php?villa=myvilla to www/villa/myvilla.php so the domain would be
http://www.site.com/villa/myvilla.php

It isn't that is makes it any more secure but that it makes it easier not to clash with other pages. Your mod_rewrite rule is a pattern and depending on what pattern you use depends on what possible clashes of pages you do not want rewritten.

So my rewrite rule for the above would be like this:


RewriteRule ^villa/([a-z-]+).php$ villa.php?villa=$1 [QSA,L]
if you had this


RewriteRule ^([a-z-]+).php$ villa.php?villa=$1 [QSA,L]
Then if you had a static page called about.php that would be redirected to villa.php.

If you use an id in the url you would do something like:


RewriteRule ^([0-9]+).([a-z-]+).php$ villa.php?id=$1&name=$2 [QSA,L]
so a url like /123.a-very-nice-villa.php would translate to
$_GET['id'] value 123
$_GET['name'] value a-very-nice-villa

edbr
04-10-2008, 09:48 AM
ok got it , i'm pretty impressed with this new toy i've found , its fried my brain a bit but thats business as usual,
anyhoo the rewrite i glued together together is
RewriteRule ^([^/]*)\.html$ /bali_districts.php?area=$1 [L]and
RewriteRule ^villa_([^/]*)\.html$ /villa.php?villa=$1 [L]