views:

137

answers:

7

At my work we have various web pages that, my boss feels, are being ranked lower than they should be because "mywebsite.org/category/" looks like a different URL to search engines than "mywebsite.org/category/index.php" does, even though they show the same file. I don't think it works this way but he's convinced. Maybe I'm wrong though. I have two questions:

  1. How do i make it so that it will say "index.php" in the address bar of all subcategories?
  2. Is this really how pagerank works?
A: 

Might want to take a look at robots.txt files? Not quite the best solution, but you should be able to implement something workable with them...

LorenVS
+1  A: 
  1. You don't tell us if you're using straight PHP or some other framework, but for PHP, probably you just need to change all the links on your site to "mywebsite.org/category/index.php".

  2. I think it's possible that this does affect your search engine rank. However, you would be better off using only "mywebsite.org/category" rather than adding "index.php" to each one.

Bottom line is that you need to make sure all your links in your website use one or the other. What actually gets shown in the address bar is unimportant.

Matthew Talbert
I would upvote you but I've used all my votes for today. :(
Imagist
+1  A: 

A simple solution is to put in the <head> tag:

<link rel="canonical" href="http://mywebsite.org/category/" />

Then, no matter which page the search engine ends up on, it will know it is simply a different view of /category/

And for your second question--yes, it can affect your results, if Google thinks you are spamming. If it wasn't, they wouldn't have added support for rel="canonical". Although I wouldn't be surprised if they treat somedir/index.* the same as somedir/

Kip
+2  A: 

Adding this code to the top of every page should also work:

<?php
if (substr($_SERVER['REQUEST_URI'], -1) == '/') {
    $new_request_uri = $_SERVER['REQUEST_URI'].'index.php';
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: '.$new_request_uri);
    exit;
}
?>
+2  A: 
  1. Besides changing all the links everywhere, a simpler solution is to use a rewrite rule. Make sure it is a permanent redirect, or Google will keep using the old link (without index.php). How you do this exactly depends on your web server, but for Apache HTTPd it looks something like the example given below.
  2. Yes. Or so I've heard. Very few people know for sure. But Google mentions this guideline (as "Be consistent"). Make sure to check out all of Google's Webmaster guidelines.

Apache config for rewrite rule:

# in the generic config
LoadModule rewrite_module modules/mod_rewrite.so

# in your virutal host
RewriteEngine On

# redirect everything that ends in a slash to the same, but with index.php added
RewriteRule ^(.*)/$ $1/index.php [R=301,L]

# or the other way around, as suggested
# RewriteRule ^(.*)/index.php$ $1/ [R=301,L]
beetstra
Fair comment. It was not the original question, that's why I used this example, but I like it better too without the 'index.php', it looks 'cleaner'.
beetstra
@migala77 yeah, deleted the comment, forgot he explicitly asked for mydir/index.php to be canonical. added it as a comment to the question instead.
Kip
+1  A: 

Hi,

I'm not sure if /category/ and /category/index.php are considered two urls for seo, but there is a good chance that it will effect them, one way or another. There is nothing wrong with making a quick change just to be sure.

A few thoughts:

URLs

Rather than adding /index.php, you will be better off making it so there is no index.php on any of them, since the keyword 'index' is probably not what you want.

You can make a script that will check if the URL of the current page ends in index.php and remove it, then forward to the resulting URL.

For example, on one of my sites, I require the 'www.' for my domain (www.domain.com and domain.com are considered two URLs for search purposes, though not always), so I have a script that checks each page and if there is no www., it ads it, and forwards.

    if (APPLICATION_LIVE) {
     if ( (strtolower($_SERVER["HTTP_HOST"]) != "www.domain.com") ) {
      header("HTTP/1.1 301 Moved Permanently"); // Recognized by search engines and may count the link toward the correct URL...
      header("Location: " . 'www.domain.com/'.$_SERVER["REQUEST_URI"] );
      exit();
     }
    }

You could mode that to do what you need.

That way, if a crawler visits the wrong URL, it will be notified that it was replaced with the correct URL. If a person visits the wrong URL, they will be forwarded to the correct URL (most won't notice), and then if they copy the url from the browser to send someone or link to that page, they will end up linking to the correct url for that page.

LINKING URLS

They way other pages link to your pages is more important for seo. Make sure all your in-site links use the proper URL (without /index.php), and that if you have a 'link to this page' feature, it doesn't include the /index.php part. You can't control how everyone links to you, but you can take some control over it, like with the script in item 1.

URL ROUTING

You may also want to consider using some sort of framework or stand-alone URL rerouting scheme. It could make it so there were more keywords, etc.

See here for an example: http://docs.kohanaphp.com/general/routing

Eli
+1  A: 

I agree with everyone who's saying to ditch the index.php. Please don't force your visitor to type index.php if not typing it could get them the same result.

You didn't say if you're on an IIS or Apache server. IIS can be set to assume index.php is the default page so that http:// mywebsite.org/ will resolve correctly without including index.php.

I would say that if you want to include the default page and force your users to type the page name in the url, make the page name meaningful to a search engine and to your visitors.

Example:

http://mywebsite.org/teaching-web-scripting.php

is far more descriptive and beneficial for SEO rankings than just

http://mywebsite.org/index.php
42