|
||
|
I'm going to detail how you get simple urls for your dynamic site. A
dynamic site, often has url's that don't sit well with all
searchengines, and thus won't be indexed. This is a bad thing :( In this document, I'm going to use phpBB2 as an example. Everything here, should be applicable for any PHP site - or with a little rewriting of the code fragments, for anything that is processed on the server-side :) Well - let's start with the apache setup: converting http://yoursite.tld/viewforum.php/f/14.html to original url (minus the sid - see below): http://yoursite.tld/viewforum.php?f=14&sid=0d48ecb4e79d1ksl653661d849983ec6 the rewriterule would look like this (untested - I don't have phpBB2 running as standalone - but you could test it without harming anyone): # this handles /*.php?somevar=somedigit RewriteRule (.*)/([A-Za-z]+)\.php/([A-Za-z]+)/([0-9]+).html$ $1/$2.php?$3=$4 [L,NC,NS] # Then we could add rewriteurl's to handle the extra options one can add - like # highlight and stuff - but seeing as this is for google benefit - I don't see # the need to right now :) The sid part is only on the forum links - not the individual topic links. I tested it without the sid - and it works just fine. AFAIK we can safely ignore the sid (ie. when rewriting urls on the way out) - otherwise there's a fix here: http://www.phpbb.com/phpBB/viewtopic.php?t=32328&highlight=sid+cookie that will leave out the sid - only for googlebot :) which should be enough to get google to index the site. Now for getting the url's rewritten so the browser(s) gets the correct url's. I use a header and a footer-file to do my url-rewriting. I based this solution on source is the simpleurl scripts available for PostNuke - rewritten by me to fit this purpose. . You could just include the header and footer file, by setting these two options in your php.ini: auto_prepend_file="/path/to/header.php" auto_append_file="/path/to/footer.php" header: call ob_start(); output whatever you want to - ie. run phpbb script as usual (if you add the header/footer to php.ini - you don't need to do anything - php will call whatever script was requested for you). footer: $contents = ob_get_contents(); ob_end_clean(); echo simplifyurls(); function simplify_urls(&$s) { // stuff to add subdir prefixes // - don't know how that works in straight phpBB2 - so it's commented out. //$base_url = pnGetBaseURL(); //$prefix = '|"(?:'.$base_url.')?'; $prefix = ''; // (?i) means case insensitive; \w='word' character; \d=digit; (amp;)? means optional; (?:catid=)? means optional and won't capture string for backreferences // NB. The first in array is replaced with the first out array line. // first array should match viewforum.php?f=(1-8 digits) with or without &(with or without amp; after)sid=(alphanumeric chars until end of line). // The second line shouldn be necessary if the first one works as planned - but only some testing will see :) $in = array( $prefix . 'viewforum.php\?f=((\d)(?:&(?:amp;)?sid=[0-9a-zA-Z]+?"|', $prefix . 'viewforum.php\?f=((\d)"|', $prefix . 'viewtopic.php\?t=((\d)"|' ); $out = array( '"viewforum.php/f/$1.html"', '"viewforum.php/f/$1.html"', '"viewtopic.php/t/$1.html"' ); $s = preg_replace($in, $out, $s); return $s; } |