Mod Rewrite does not work with Version 4/4-04?

Use GitHub to post bug reports and error descriptions for phpwcms. Describe your problem detailed!
Locked
cmslover
Posts: 86
Joined: Wed 18. Feb 2004, 16:17
Location: USA, Georgia, Atlanta
Contact:

Mod Rewrite does not work with Version 4/4-04?

Post by cmslover »

Live site: http://realestatebuyingselling.com/home

Detail error: 404 URL not found

Then I Tried:
1/Enable .htacess with code:

Code: Select all

RewriteEngine on 
RewriteBase /home
# This will rewrite 0.0.0.0.0.html => index.php?id=0.0.0.0.0 
RewriteRule ^([0-9]*).([0-9]*).([0-9]*).([0-9]*).([0-9]*).([0-9]*).html$ /home/index.php?#id=$1.$2.$3.$4.$5.$6 

# This will rewrite mypage.html => index.php?mypage 
RewriteRule ^(.*).html$ /home/index.php?$1 
===> Result: Click on all links on the left menu they would change the name.html correctly, BUT the page content would not change. All remain the same index page

2/Still keep that .htacess above,
Now I went to front.func.inc and change the code from:

Code: Select all

//Rewrite functions
function url_search($query)    
{ 
   $noid = substr($query, 4); 
  $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
  $link = "<a href=\"".$file."\""; 
  return($link); 
   //unset($link); 
} 

function js_url_search($query)    
{ 
   $noid = substr($query, 4); 
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
  $link = "onClick=\"location.href='".$file."'"; 
  return($link); 
   //unset($link); 
} 

to the code based on Pixelpeter method:

Code: Select all

function url_search($query) 
{ 
if ( subStr($query,0,4) == "?id=") 
{ 
// this is for id=0,0,0,0,0 
$noid = substr($query, 4); 
$file = str_replace(",", ".", $noid).".html"; //further use 
} 
else 
{ 
// this is for mypage.html 
$noid = substr($query,1); 
$file = str_replace(",", ".", $noid).".html"; //further use 
} 
$link = "<a href="".$file."""; 
return($link); 
} 

===>Result: Error call to un-define function



Any idea, please?
(I wish Oliver enhanced this function in the core version :o )
Thanks
gent
Posts: 165
Joined: Tue 16. Dec 2003, 13:51
Location: Berlin

Post by gent »

for me the rewrite dont work too, but on a different way...

if i click on the left menu directly over the linked text, then i will get the page .. i noted, that the link is changed from 1.0.0.html to alias.html

.. but if i click the same line over the tablerow .. mouse is not over the text but over the same line with link-active row, then i cant get the page. i will get the index of my site. cause it will try to load as.html
(the first 3 chars from the "alias" are missing)

maybe i will go back to my backup, cause i dont need the new features of this release, but i need a working rewrite for google.
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post by Jan212 »

Hello everybody,

1.The rewrite function is definitly working with all releases, include the releas fom the 04-04-2004.
I have it running on every version.
2.The function is included in the next release (guaranteed) and it doesn't have to be enhanced because it's working perfect.

in your case the problem perhaps is that you named your .htaccess -> .htacess -> first mistake
or 2nd reason because of the missing

Code: Select all

DirectoryIndex index.php
or the 3rd reason could be because you've cut out the function js_url_search($query) after the function url_search

Code: Select all

//Rewrite functions / modded 02.03.04
function url_search($query)    
{ 
   if ( subStr($query,0,4) == "?id=") 
   { 
      // this is for id=0,0,0,0,0 
      $noid = substr($query, 4); 
      $file = str_replace(",", ".", $noid).".html"; //further use 
   } 
   else 
   { 
      // this is for mypage.html 
      $noid = substr($query,1); 
      $file = str_replace(",", ".", $noid).".html"; //further use 
   } 
   $link = "<a href=\"".$file."\""; 
   return($link); 
} 

function js_url_search($query)    
{ 
   $noid = substr($query, 4); 
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
   $link = "onClick=\"location.href='".$file."'"; 
   return($link); 
   //unset($link); 
} 

// -------------------------------------------------------------


And now I'm rocking...


REWRITE FOR DUMMIES II

Change the function url_search in front.func.inc.php

Code: Select all

function url_search($query) 
{ 
if ( subStr($query,0,4) == "?id=") 
{ 
// this is for id=0,0,0,0,0 
$noid = substr($query, 4); 
$file = str_replace(",", ".", $noid).".html"; //further use 
} 
else 
{ 
// this is for mypage.html 
$noid = substr($query,1); 
$file = str_replace(",", ".", $noid).".html"; //further use 
} 
$link = "<a href="".$file."""; 
return($link); 
} 





In .htaccess

Code: Select all

RewriteEngine on 

# if you're in a subdirectory named "beta" add the rewriteBase 
#RewriteBase /beta 

# This will rewrite 0.0.0.0.0.html => index.php?id=0.0.0.0.0 
RewriteRule ^([0-9]*).([0-9]*).([0-9]*).([0-9]*).([0-9]*).([0-9]*).html$ /index.php?id=$1.$2.$3.$4.$5.$6 

# This will rewrite mypage.html => index.php?mypage 
RewriteRule ^(.*).html$ /index.php?$1 





EXAMPLE:
You call your Site like http://www.example.com/mysubdir/index.php

You need to modify the rules as followed:

Code: Select all

RewriteEngine on 
RewriteBase /mysubdir 

# This will rewrite 0.0.0.0.0.html => index.php?id=0.0.0.0.0 
RewriteRule ^([0-9]*).([0-9]*).([0-9]*).([0-9]*).([0-9]*).([0-9]*).html$ /mysubdir/index.php?id=$1.$2.$3.$4.$5.$6 

# This will rewrite mypage.html => index.php?mypage 
RewriteRule ^(.*).html$ /mysubdir/index.php?$1 
logging the rewrite, ad this to the .htaccess

Code: Select all

RewriteLog "/absolute/path/to/the/rewrite.log" 
# 0 = Logging disabled, 9 = highest level of logging, only for debugging 
RewriteLogLevel 3 

If you have installed my Quick-Hack for rewriting this next hack should be also fine for you: Using Alias-Names in the Navigation


File: /include/inc_front/front.func.inc.php
Line: 511
function name: get_struct_data
desc:We will add the "acat_alias" to the struct wich is used for building the menu. I did this at the end of each field-list. You can copy the complete function from here

Code: Select all

function get_struct_data ($dbcon, $root_name="Home", $root_info="") { 
//returns the complete active and public struct data as array 
//so it is reusable by many menu functions -> lower db access 
$data[0] = array( "acat_id" => 0, 
"acat_name" => $root_name, 
"acat_info" => $root_info, 
"acat_struct" => 0, 
"acat_sort" => 0, 
"acat_hidden" => 0, 
"acat_regonly" => 0, 
"acat_ssl" => 0, 
"acat_template" => 0 , 
"acat_alias" => 0 
); 
$sql = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE ". 
"acat_aktiv=1 AND acat_public=1 AND acat_trash=0 ORDER BY acat_struct, acat_sort;"; 
if($result = mysql_query($sql, $dbcon)) { 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
$data[$row["acat_id"]] = array( "acat_id" => $row["acat_id"], 
"acat_name" => $row["acat_name"], 
"acat_info" => $row["acat_info"], 
"acat_struct" => $row["acat_struct"], 
"acat_sort" => $row["acat_sort"], 
"acat_hidden" => $row["acat_hidden"], 
"acat_regonly" => $row["acat_regonly"], 
"acat_ssl" => $row["acat_ssl"], 
"acat_template" => $row["acat_template"], 
"acat_alias" => $row["acat_alias"], 
); 
} 
mysql_free_result($result); 
} 
return (sizeof($data)) ? $data : array(); 
} 


File: /include/inc_front/front.func.inc.php
Line: 669
function name: build_levels
desc:In line 705 we will change the var $link to prepare for using aliase. You can copy this line from here. I left the original untouched to have the chanche to go back

Code: Select all

// $link = $link_to."?id=".$key.",0,0,1,0,0"; 
$link = $link_to."?".$struct[$key]['acat_alias']; 
--------------------------------------------------------------------------------------

PACE
Regards/ Grüsse/ Groetjes - JAN212
------------------------------------------------
null212 - Büro für Kommunikation und Design
------------------------------------------------
Lyrikfetzen des Tages
1. Ist der Quelltext auch valide fragt Herr Müller ganz perfide.
2. Wat is dat een lekker ding.
3. Wer Vision hat soll zum Arzt gehen.
------------------------------------------------
gent
Posts: 165
Joined: Tue 16. Dec 2003, 13:51
Location: Berlin

Post by gent »

@cmslover

i guess u get the "Error call to un-define function" cause u changed the "function js_url_search($query)" too. but u only have to change the "function url_search($query)".

my front.func.inc.php looks like this:

Code: Select all

//Rewrite functions
function url_search($query) {
	if ( subStr($query,0,4) == "?id=") {
		$noid = substr($query, 4);
		$file = str_replace(",", ".", $noid).".html";
		}
	else {
		$noid = substr($query,1);
		$file = str_replace(",", ".", $noid).".html";
	}
	$link = "<a href=\"".$file."\"";
	return($link);
}

// ORIGINAL !!!
/*function url_search($query)    
{ 
   $noid = substr($query, 4); 
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
   $link = "<a href=\"".$file."\""; 
   return($link); 
   //unset($link); 
} */



function js_url_search($query)    
{ 
   $noid = substr($query, 4); 
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
   $link = "onClick=\"location.href='".$file."'"; 
   return($link); 
   //unset($link); 
} 
but i think i know why the links are different on my page.

...if i click over the chars of the menu-link then it will use the changed "function url_search($query)". but if i click over the table-row then it will use the "function js_url_search($query)"? maybe this have to be changed too? same way like the "function url_search($query)"?

i hope Pixelpeter will read this and will give us the answer :)
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post by Jan212 »

yes, in this case you'll have to change it the same way - but not if you're using nav_column...
and replace the old rewrite function from the code
Regards/ Grüsse/ Groetjes - JAN212
------------------------------------------------
null212 - Büro für Kommunikation und Design
------------------------------------------------
Lyrikfetzen des Tages
1. Ist der Quelltext auch valide fragt Herr Müller ganz perfide.
2. Wat is dat een lekker ding.
3. Wer Vision hat soll zum Arzt gehen.
------------------------------------------------
gent
Posts: 165
Joined: Tue 16. Dec 2003, 13:51
Location: Berlin

Post by gent »

Jan212 wrote:yes, in this case you'll have to change it the same way - but not if you're using nav_column...
and replace the old rewrite function from the code
sorry, but i dont know what u mean.

at the old release the rewrite-link in the left menu looks like this "0.0.0.0.0.0.html" .. but in the new release the link looks like "alias.html"

... for sure only by clicking over the chars of the link

what exactly mean "and replace the old rewrite function from the code" ?

in my case changing the functions to the following will work with all links correctly:

Code: Select all

// -------------------------------------------------------------

//Rewrite functions
function url_search($query) {
	if ( subStr($query,0,4) == "?id=") {
		$noid = substr($query, 4);
		$file = str_replace(",", ".", $noid).".html";
		}
	else {
		$noid = substr($query,1);
		$file = str_replace(",", ".", $noid).".html";
	}
	$link = "<a href="".$file.""";
	return($link);
}

function js_url_search($query) {
	if ( subStr($query,0,4) == "?id=") {
		$noid = substr($query, 4);
		$file = str_replace(",", ".", $noid).".html";
	} else {
		$noid = substr($query,1);
		$file = str_replace(",", ".", $noid).".html";
	}
	$link = "onClick="location.href='".$file."'";
	return($link);
}

// ORIGINAL !!!
/*function url_search($query)    
{ 
   $noid = substr($query, 4); 
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
   $link = "<a href="".$file."""; 
   return($link); 
   //unset($link); 
} 

function js_url_search($query)    
{ 
   $noid = substr($query, 4); 
   $file = str_replace(",", ".", $noid).".html"; //further use 
   //$file = $noid.".html"; 
   $link = "onClick="location.href='".$file."'"; 
   return($link); 
   //unset($link); 
} */

// -------------------------------------------------------------
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post by Jan212 »

-the front.func.inc function get_struct_data is allready uppatched to this in V 04-04 because of this you see alias.html instead of 1.0.1...html
-with replace i meant cut them out instead of comment them out
Regards/ Grüsse/ Groetjes - JAN212
------------------------------------------------
null212 - Büro für Kommunikation und Design
------------------------------------------------
Lyrikfetzen des Tages
1. Ist der Quelltext auch valide fragt Herr Müller ganz perfide.
2. Wat is dat een lekker ding.
3. Wer Vision hat soll zum Arzt gehen.
------------------------------------------------
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

h iguys - i think the reason for this mod not working is that in pixelpeters code (as seen on jan's site) there is an error with nested quotes...

Code: Select all

 $link = "<a href="".$file.""";
should be

Code: Select all

 $link = "<a href=\"".$file."\"";
notice the backslashes?
i'm not sure where else this code appears in the forums as i only checked jan's site (nice and helpfull site too jan 8) )
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

hi guys
i'm not sure where else this code appears in the forums as i only checked jan's site (nice and helpfull site too jan 8) ) but i have noticed that the code (as seen on jan's site) there is an error with nested quotes...

Code: Select all

 $link = "<a href="".$file.""";
should be

Code: Select all

 $link = "<a href=\"".$file."\"";
notice the backslashes?
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post by pSouper »

did you all get this fixed?
also..were there further amendments made to the front.func.inc that were made via email
would you post the problems solution for others (and me) to read too please? thanks
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post by Jan212 »

i've it working without your corrections on a 04.04 version as you can see on http://null212.de...
the only bugfix is...

Code: Select all

// ------------------------------------------------------------- 

//REWRITE - PATCHED FOR 04/04 //JAN212
function url_search($query) { 
   if ( subStr($query,0,4) == "?id=") { 
      $noid = substr($query, 4); 
      $file = str_replace(",", ".", $noid).".html"; 
      } 
   else { 
      $noid = substr($query,1); 
      $file = str_replace(",", ".", $noid).".html"; 
   } 
   $link = "<a href=\"".$file."\""; 
   return($link); 
} 

function js_url_search($query) { 
   if ( subStr($query,0,4) == "?id=") { 
      $noid = substr($query, 4); 
      $file = str_replace(",", ".", $noid).".html"; 
   } else { 
      $noid = substr($query,1); 
      $file = str_replace(",", ".", $noid).".html"; 
   } 
   $link = "onClick=\"location.href='".$file."'"; 
   return($link); 
} 
the update of the java fs to enable rewrite while clicking on a navigation icon

my question - who has problems with the rewrite function and the current release - plz post ya feedback
Regards/ Grüsse/ Groetjes - JAN212
------------------------------------------------
null212 - Büro für Kommunikation und Design
------------------------------------------------
Lyrikfetzen des Tages
1. Ist der Quelltext auch valide fragt Herr Müller ganz perfide.
2. Wat is dat een lekker ding.
3. Wer Vision hat soll zum Arzt gehen.
------------------------------------------------
Locked