Page 1 of 2

A Quick Hack for the rewrite function working with alias too

Posted: Tue 2. Mar 2004, 21:35
by pixelpeter
I also don't have enough time to get the right solution, but this one will work !! It's a bit unusual, but the result is whats counting :o 8)

The problem is that both rewrite rules in the .htaccess-file are going to modify our URL regardless if it's of the type 0.0.0.0.0.html or mypage.html.

The base idea is to change the URL to make it different for the rewrite rules !!! You don't understand ?? You will in 1 minute

We change the url_search function to generate a URL with an .htm ending for the 0.0.0.0-type and an .html ending for the mypage-type, so the rules will only match once. It's really simple :lol:


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

Code: Select all

Line: 1185
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).".htm"; //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); 
}
No we need these rules in the .htaccess-file

Code: Select all

DirectoryIndex index.php

RewriteEngine on

# if your in an subdirectory called "phpwcms" define the rewrite-base
# RewriteBase /phpwcms

# This will rewrite 0.0.0.0.0.html => index.php?id=0.0.0.0.0
RewriteRule ^(.*)\.htm$ /index.php?id=$1

# This will rewrite mypage.html => index.php?mypage
RewriteRule ^(.*)\.html$ /index.php?$1
If have tested this on WIN2K and SUSE Linux 7.x and it's working.
I've tested only with normal URLs, maybe we need to rework the PopUp and JavaScript-Functions too.

What do you think ??

Is it working for you ??

Please let me know !!!

[ p i x e l p e t e r ]

Posted: Tue 2. Mar 2004, 23:25
by Jan212
AWESOME, GREAT USAGE...
Thank you very much for this contribution. It is a better solution than mine. Post it at Ionrocks Contribution page too, maybe Olli would implement this in the new patch...
PIXELPETER FOR PRESIDENT 2...

BEST REGARDS

Posted: Wed 3. Mar 2004, 00:09
by ionrock
very nice. do you mind if I write it up and post it on my site?

http://ionrock.umemusic.com/index.php?develphpwcms

Some links may not work at the moment b/c I need to get my url rewrite worked out :) so this comes at a very good time

doesn't work for me...

Posted: Wed 3. Mar 2004, 00:17
by valjah
i tried your hack for the rewrite function but it doesn't work, i still get 404s...
- mod_rewrite is on and works with other applications
- rewrite function is turned on in the conf.inc.php
in fact, i could not get the rewrite function for phpwcms to work with any of the solutions offered in this forum.

my system: win2k, apache 2.0.48, php 4.3.4

thanks for your help,

valjah

Posted: Wed 3. Mar 2004, 00:28
by pixelpeter
Sorry, my fault !!! I forgot to say this was tested with Apache 1.x.x and is not working with 2.x :x

I will get back to you with the solution as soon as my cat is leaving the kask dlsdal vbn keyboard :lol:

Posted: Wed 3. Mar 2004, 00:39
by Jan212
i have the following specs:
Apache/2.0.48 (Win32) mod_perl/1.99_10 Perl/v5.8.0 mod_ssl/2.0.48 OpenSSL/0.9.7c PHP/4.3.4
and it works funky...

best regards

Posted: Wed 3. Mar 2004, 01:02
by pixelpeter
I just installed Apache 2.0.48 with php 4.3.1 and it's workng without any modifications.

Can you review the Apache Error Log ??
There must something be in there saying us whats wrong !!!

Maybe you can try first with simple aliases containing only letters ?!?

Posted: Wed 3. Mar 2004, 01:22
by pixelpeter
Variation on this Hack:

If you depend on the extension .html you just only need to change this hack slightly:

In front.func.inc.php
Just define both extensions as .html

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
We just use a different rule for the 0.0.0.0.0.0.html-type URL

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
Be sure that everything is typed correctly !!!

If you're in an subDirectory you need to define the RewriteBase
!! Also you need to add the subDirectory to the Rewriting Rule !!

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
For all you out there who want to stop guessing whats going wrong:

Define a RewriteLog in the Apache-Configuration the httpd.conf.
This will not work in .htaccess

Code: Select all

RewriteLog "/absolute/path/to/the/rewrite.log"
# 0 = Logging disabled, 9 = highest level of logging, only for debugging
RewriteLogLevel 3
Now you can see whats coming in, what kind of magic happens, and whats send back !!!

Have Fun ! :twisted: :twisted:

works now!

Posted: Wed 3. Mar 2004, 01:32
by valjah
thanks to pixelpeter's detailed explanation i finally got it to work. i had defined the subdirectory in the RewriteBase, but i forgot to do it in the RewriteRule...
another problem solved

Posted: Wed 3. Mar 2004, 07:59
by cmslover
sorry to ask: Where to put the.htaccess file? In the root ( mydomain.com )
or in directory where I installed phpwcms ?

Thanks much!


Update1: I put the htacess file in the directory where I installed phpwcms and it worked!!! :P

Update 2: But the alias does not work. What is missing?

Question: now the uRL is /phpwcms/4.0.0.1.0.0.htm, Is there a way to change those NUMBER to a MEANING NAME such as BOOK.htm? In the other word, if we name a file name as BOOK, SCHOOK, TAPE.... PHPwcms will automatically generate the output URLs just like that: domain/tape.htm.....

Thank you very much Pixelpeter!!!

Posted: Wed 3. Mar 2004, 08:17
by pixelpeter
In the directory where you installed phpwcms

Posted: Sat 6. Mar 2004, 18:14
by LANtastic
Sorry but I still have a problem woth that modification.

At first 1 tried pixelpeter's first posted modification.
I modified the function url_search in front.func.inc.php
Then I modified the .htaccess file

But there are no visible changes when I check my links.
There is still written

index.php?id=1,0,0,0,0

instead of

1.0.0.0.0.html

But when I call the adress 1.0.0.0.0.html by typing it in the adress bar I see the correct page. It's just a question of creating those links automaticly.
Maybe I didn't correctly understand the idea behind that modification.

Posted: Sat 6. Mar 2004, 18:23
by pixelpeter
You have to set $phpwcms["rewrite_url"] = 1 in your include/in_conf/conf.inc.php to make it work automagically ;-)

Posted: Sat 6. Mar 2004, 21:06
by LANtastic
That has been the Problem, thanks !

Posted: Mon 22. Mar 2004, 17:19
by gent
if i copy/paste the code to front.func.inc.php i get a parse-error.
but without the changes in front.func.inc.php it is working.

but if i use [ID kontakt]click[/ID] the link will be */takt.html
the first 3 chars of the alias will be lost.