Page 1 of 1

HOW2 - create bot-friendly URL

Posted: Tue 2. Mar 2004, 20:43
by Jan212
Hello everbody,
this is no bugfix, my solution is hardcoded but is working as well...
The rewrite function isn't working with the alias function at the time, but this simple script will cause the same effect.
Enable the rewrite engine in includes/inc_conf/config.inc.php...
This hack is only concepted for better indexing of the main categories, but with a little bit of work it can be used for the whole system...
Add In your .htacces

Code: Select all

RewriteEngine On
RewriteBase /phpwcms_1.1/ 
RewriteRule ^anfragen.html$ index.php?id=1
RewriteRule ^([a-z]*)\.html$ index.php?id=$1
RewriteRule ^(.*)\.html$ index.php?id=$1
Code expl.
Line1: to enable mod_rewrite -
check it in your phpinfo under -> apache if it is enabled, otherwise go to your apache/conf/httpd.conf an enable it.

Line 2: the base of the files that have to be rewritten -
example: in case of http://myhost.de/phpwcms_1.1/ the RewriteBase is /phpwcms_1.1/

Line3
^ = Beginning of the loop
anfragen.html = the name of the file which you want to create
$ = End of the loop
index.php?id=1 = the ID of the categorie/article you want to rename- if you want to rename an article fill in this index.php?id=1,1,0,0,1,0 for example

Line4&5
These rules must be set to create files like 1.12.1.0.1.1.html.
I will use it for the news etc.
Please make sure that your indication classes(zeichenklassen)are set correctly.

In includes/inc_front/front.func.inc.php
replace your code with this...

Code: Select all

//Rewrite functions

function url_search($query)   
{ 
   if(strpos($query, "id")) $noid = substr($query, "4");
   else $noid = substr($query, "1");
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
   $link = "<a href=\"".$file."\""; 
   return($link); 
  //unset($link); 
}
You can also use [ID alias]string[/ID], the url will be transfered correct into ya browser, but the content is only shown if you define the rewrite rule in ya .htaccess...

That's all - best regards

A yockl from the deepest backwood of germany

Posted: Tue 2. Mar 2004, 21:53
by ionrock
I like the tutorial but I think there is a problem. I tried the .htaccess file and changing the url rewrite but in my case I use aliases for my main menu links. For example I had links to index.php?downloads and index.php?links. This is different from the articles because articles are formed by having index.php?id=1,0,0,0,4 where there is an id varaible passed. This shouldn't be a problem with a little regex in the .htaccess but it is still an issue it seems. I could be missing somethings though so please explain or send a link to more expanation of how we can deal with this issue. Thanks for the tutorial, I had just been working on mod_rewrite so it was a big help :)

Posted: Tue 2. Mar 2004, 23:05
by Jan212
Hello
You can also work with an alias, the codefix in front.function.inc.php enable this... The internal rewrite function is making anschrift.html from index.php?anschrift.
Best Regards

Posted: Tue 2. Mar 2004, 23:19
by Jan212
:arrow: ATTENTION
--------------------------------------------------------------
THERE IS A BETTER SOLUTION BY PIXELPETER
HERE
--------------------------------------------------------------
THANKS TO HIM, AWESOME

BEST REGARDS