Forums / Cotonti / Support / url mod_rewrite page_add bug

<<<123

question about page_add bug solving with mod_rewrite enabled

GHengeveld
#31 2010-03-07 05:20
Using a custom function for URL rewriting is a very powerful feature, but requires quite some skill and knowledge to apply correctly. I've never used it myself, so it's beyond my knowledge, even though I use the rewriting system a lot.

Added 24 minutes later:

Come to think of it, I don't think it's possible to rewrite the main url, for editing the subdomain.

You can still do it through .htaccess, but that won't really rewrite the url, only redirect the visitor so it seems to him there was a subdomain specified.
- Cotonti rewrite to www.domain.com/cat/subcat
- .htaccess rewrite www.domain.com/cat/subcat to cat.domain.com/subcat, with [R=301] specified
- .htaccess rewrite cat.domain.com/subcat to www.domain.com/list.php?c=subcat without [R=301]
This post was edited by Koradhil (2010-03-07 05:45, 14 years ago)
donP
#32 2010-03-07 23:19
I was able to modify function.custom.php like this:
function list_url_structure(&$args)
{
	global $sed_cat;
	
	$url = str_replace('.', '/', $sed_cat[$args['c']]['path']).'/';
	unset($args['c']);
	
	$subdomain = substr($url, 0, strpos($url,"/"));
	$restofurl = substr($url, strpos($url,"/")+1);
	return "http://".$subdomain.".sangelo.net/".$restofurl;
}
so it returns cat.domain.net/subcat...

Now I would find anyone to help me modifying .htacces from
# Level 3
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/([a-z\-]+)/([0-9]+)\.html page.php?id=$4 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/([a-z\-]+)/add$ page.php?m=add&c=$3 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/([a-z\-]+)/([a-zA-Z0-9\-_]+)\.html page.php?al=$4 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/([a-z\-]+)/ list.php?c=$3 [QSA,NC,NE,L]

# Level 2
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/([0-9]+)\.html page.php?id=$3 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/add$ page.php?m=add&c=$2 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/([a-zA-Z0-9\-_]+)\.html page.php?al=$3 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-z\-]+)/ list.php?c=$2 [QSA,NC,NE,L]

# Level1
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([0-9]+)\.html page.php?id=$2 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/add$ page.php?m=add&c=$1 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/([a-zA-Z0-9\-_]+)\.html page.php?al=$2 [QSA,NC,NE,L]
RewriteRule ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari)/ list.php?c=$1 [QSA,NC,NE,L]

to the new rules to reflect my modifications in function.custom.php and give funcionality to my "subdomains rewrite"...

Added 23 hours 47 minutes later:

I was good in redirecting to http://cat1.sangelo.net with this rule:

RewriteCond %{HTTP_HOST} ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari).sangelo.net [NC]
RewriteRule (.*) list.php?c=%1 [L] 

but I'm not able to create second and third level of folder (e.g. htt://cat1.sangelo.net/subcat1/ and http://cat1.sangelo.net/subcat1/subsubcat1/ ) cause, using such a rule:

RewriteCond %{HTTP_HOST} ^(Parrocchia|Oratorio|SocietaSportiva|Scout|RnB|links|ECOComunita|news|Diari).sangelo.net/([a-z\-]+)/ [NC]
RewriteRule (.*) list.php?c=%2 [L] 

I obtain a 404 not found error, cause, as I can see from error log, that rewrite rule causes a
File does not exist: /home/sangelon/public_html/subcat, referer: http://cat1.sangelo.net/
:(

Added 20 hours 44 minutes later:

Nobody can help me here... I think I must search on the web for an Apache mod_rewrite expert...
in [color=#729FCF][b]BLUES[/b][/color] I trust
This post was edited by donP (2010-03-10 21:59, 14 years ago)
GHengeveld
#33 2010-03-11 01:06
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9\-]+).sangelo.net$ [NC]
RewriteRule ^([a-z\-]+)$ list.php?c=$1 [NE,NC,L,QSA]
I'm pretty good with mod_rewrite, but it always requires testing and tweaking.
pieter
#34 2010-03-11 15:22
Is there some explaination on another site maybe about how these things work.

^([A-Za-z0-9\-]+
I saw it also in bbcodes, but I don't have a clue what it really means.
... can we help you ...
donP
#35 2010-03-11 16:18
# Koradhil :
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9\-]+).sangelo.net$ [NC]
RewriteRule ^([a-z\-]+)$ list.php?c=$1 [NE,NC,L,QSA]
I'm pretty good with mod_rewrite, but it always requires testing and tweaking.
Your syntax doesn't take me to list.php?c=$1 but to homepage...
the right syntax was mine:
RewriteCond %{HTTP_HOST} !www.sangelo.net$ [NC]
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9\-]+).sangelo.net$ [NC]
RewriteRule (.*) list.php?c=%1 [NE,NC,L,QSA]

But my problem was not to first level, that I personally already solved like that...
The problem is for second and third level, rewriting
http://cat1.sangelo.net/subcat/ redirecting to list.php?c=subcat
and
http://cat.sangelo.net/subcat/subsubcat redirecting to list.php?c=subsubcat

'cause a rule like the one below:
RewriteCond %{HTTP_HOST} ^([A-Za-z0-9\-]+).sangelo.net/([A-Za-z0-9\-]+)$ [NC]
RewriteRule (.*) list.php?c=%2 [NE,NC,L,QSA]
still redirects to list.php?c=cat

Personally I think it's a problem concerned with subdomain form in url, cause, also when rewriting http://cat.sangelo.net (that right takes me to list.php?c=cat) I have problems in displaying images, cause .tpl files address images to /skin/skinname/img/imagefile.jpg, not to the complete domain url including http://www.sangelo.net... so, also that is a real problem (I would have to correct all tpl files, hoping that we haven't too many hardcoded images that I would have to correct with core hacks)...
in [color=#729FCF][b]BLUES[/b][/color] I trust

<<<123