View Full Version : Mod_Rewrite guru help needed
eva2000 07-06-2002, 03:59 PM Hi i need a mod_rewrite/regular expressions guru's help :)
I'm moving my vB forums to a new server from
RH 6.2
2.2.19 SMP kernel
Apache 1.3.26
PHP 4.1.2
MySQL 3.23.45
Cpanel/whm with SuExec disabled (WHM 4.8.0 /Cpanel 4.8.0-80)
to
RH 7.3
2.4.18 SMP kernel
Apache 1.3.26
PHP 4.1.2
MySQL 3.23.51
Cpanel/whm with SuExec enabled (WHM 4.8.0 /Cpanel 4.8.0-80)
and in my forum's <VirtualHost></VirtualHost> entry at the bottom i have for shorter vB urls
RewriteEngine on
RewriteRule ^/f([0-9]+)/?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/f([0-9]+)/s?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/t([0-9]+)\.html$ /showthread.php?threadid=$1 [L]
RewriteRule ^/t([0-9]+)/s([^/]+?)\.html$ /showthread.php?threadid=$1&s=$2 [L]
RewriteRule ^/s([^/\?]0-9)+?/$ /index.php?s=$1 [L]
they would work on my original server.
but on my RH 7.3 server when i restart apache, the last 2 lines cause errors and apache doesn't restart.
RewriteEngine on
RewriteRule ^/f([0-9]+)/?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/f([0-9]+)/s?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/t([0-9]+)\.html$ /showthread.php?threadid=$1 [L]
above first 3 lines are okay
last 2 lines have problems
RewriteRule ^/t([0-9]+)/s([^/]+?)\.html$ /showthread.php?
threadid=$1&s=$2 [L]
i get this error
Syntax error on line 1691 of /usr/local/apache/conf/httpd.conf:
RewriteRule: cannot compile regular expression '^/t([0-9]+)/s([^/]+?)
\.html$'
RewriteRule ^/s([^/\?]0-9)+?/$ /index.php?s=$1 [L]
I get this error
Syntax error on line 1692 of /usr/local/apache/conf/httpd.conf:
RewriteRule: cannot compile regular expression '^/s([^/\?]0-9)+?/$'
currently my vB forum's urls on my RH 6.2 server are in the format
http://forumdomain.com/f1/s
http://forumdomain.com/t42538/s.html
any mod_rewrite gurus who can tell me how fix this for my new server ?
any help is very much appreciated :D
eva2000 07-07-2002, 02:54 AM bump
We're not gonna help you until you stop using a MySQL thats compiled under gcc 2.96:) :) :rolleyes: :D
Jedito 07-07-2002, 08:39 AM Sorry, I can't help you with the setting, but why don't you use .htaccess instead of in the <virtualhost>?
I mean, you wont have the problem of bring apache down, also its a lot easier to edit than httpd.conf :)
eva2000 07-07-2002, 08:40 AM huh ? :confused:
mysql 3.23.50 and higher rpm binaries are compiled using gcc 3.04
Ahmad 07-07-2002, 11:42 AM From what I can see, this is because of the question mark:
^/s([^/\?]0-9)+?/$
The question mark in that context is to prevent greediness by the regex engine, but it is not supported in the standard regex, only in Perl regex.
AFAIK, Apaches uses standard regex.
What I can't understand is why did it work on your older machine :confused:
Maybe there is a compile time option to let Apache use perl regex instead of standard regex, and it was used with your old system and not with your new system.
Anyway, change the patterns to these and lets see what happens:
RewriteRule ^/t([0-9]+)/s([^/]+)\.html$ /showthread.php?threadid=$1&s=$2 [L]
RewriteRule ^/s([^/\?]0-9)+/$ /index.php?s=$1 [L]
BTW, I can't see why do you need the '?' in the first place.
eva2000 07-07-2002, 01:34 PM thanks for the help guys... will try it out just ran into a kernel bug on the new server getting that fixed first :)
Originally posted by eva2000
huh ? :confused:
mysql 3.23.50 and higher rpm binaries are compiled using gcc 3.04
mysql.com said dont use 3.0/3.1 also
eva2000 07-08-2002, 09:59 AM yes that was earlier... however if you note it's mysql.com that actual says they use gcc 3.04 for rpm binaries from mysql 3.23.50 onwards ;)
eva2000 07-08-2002, 10:40 AM thanks i finally got it to work with a ? instead of +
RewriteEngine on
RewriteRule ^/f([0-9]+)/?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/f([0-9]+)/s?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/t([0-9]+)\.html$ /showthread.php?threadid=$1 [L]
RewriteRule ^/t([0-9]+)/s([^/]?)\.html$ /showthread.php?threadid=$1&s=$2 [L]
RewriteRule ^/s([^/\?]0-9)+/$ /index.php?s=$1 [L]
elsmore1 07-08-2002, 11:08 AM Originally posted by eva2000
thanks i finally got it to work with a ? instead of +
RewriteEngine on
RewriteRule ^/f([0-9]+)/?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/f([0-9]+)/s?$ /forumdisplay.php?forumid=$1 [L]
RewriteRule ^/t([0-9]+)\.html$ /showthread.php?threadid=$1 [L]
RewriteRule ^/t([0-9]+)/s([^/]?)\.html$ /showthread.php?threadid=$1&s=$2 [L]
RewriteRule ^/s([^/\?]0-9)+/$ /index.php?s=$1 [L]
You may have gotten Apache to start using these rules, but do they actually work as intended? Looks broken to me. :) In particular the last two rules.
Ahmad 07-08-2002, 12:14 PM will ..
? (generally) means zero or one times ..
* means zero or one times ..
+ means one or more times ..
These (above) are called quantifiers ..
In perl, there is an extension to the standard regex that lets you add a question mark after a quantifier to stop the regex engine from being greedy and skip the first match it finds looking for longer matches.
What you were originally doing is using the question mark instead after a quantifier ( which is the plus sign ). it was acting like an ungreedy character ..
What you are doing now is removeing the original quantifier ( + ) and leaving the question mark.
The question mark now doesn't appear after a quantifier so it is acting like a quantifier now meaning ( zero or one times ) ..
that will totally change the meaning of the regex ..
what you should really do is to leave the +'s and remove the ?'s.
Did i type too much :confused:
eva2000 07-08-2002, 12:44 PM thanks but leaving the + it doesn't work for my forum urls for my vB which are rerwritten to
forumdomain.com/fxx
forumdomain.com/fxx/s
where xx is the forumid
or
forumdomain.com/tyy/s.html
forumdomain.com/tyy.html
where yy is the threadid
with the ? it works *** shrugs shoulders ***
Ahmad 07-08-2002, 12:53 PM I see ..
forumdomain.com/tyy/s.html
you are sure the url's doesn't contain anything between the s and the .html? like in:
s1.html
sx.html
If you don't, then you are actually including a large part to your pattern and makeing it optional while you don't need it at all.
eva2000 07-08-2002, 01:17 PM well it can have something after the s, since vB also has sessionhashes if you browse using sessions instead of cookies
elsmore1 07-08-2002, 02:27 PM RewriteRule ^/s([^/\?]0-9)+/$ /index.php?s=$1 [L]
Above Rule will take a URL of the form
http://example.com/sH0-9/
where the URI begins with /s
followed by any character which is not either a /, \, or ?
followed by the string "0-9" and
optionally followed by more combinations of a single character (not /\?) and the string "0-9"
and finally ending in a trailing slash.
and will convert the above URL to...
http://example.com/index.php?s=H0-9
Is that what you are trying to do?
The Prohacker 07-08-2002, 08:59 PM An example of how the links look is like this:
webhostingtalk.com/t59209/s4545646546465454564566.html
webhostingtalk.com/showthread.php?s=4545646546465454564566&threadid=59209
Those would be equal..
elsmore1 07-08-2002, 10:11 PM After re-reading my post above, I can see where i wasn't very clear about what I was asking.... so I'll try again. :)
In the "fixed" set of rules eva2000 posted, the last rule is...
RewriteRule ^/s([^/\?]0-9)+/$ /index.php?s=$1 [L]
which would re-write...
webhostingtalk.com/sA0-910-930-9w0-9/
to...
webhostingtalk.com/index.php?s=A0-910-930-9w0-9
but it would have no effect on...
webhostingtalk.com/s4518ec4b4a527f9d3061ec9edb0a7f9e/
Since the first URL (which it would re-write) looks like kind of a strange format for a vbulletin URL, I suspect that the regex should be modified in the rewrite rule, or it is likely that the rule will never match. I don't know though. Maybe such a URL is possible?
I would have thought that the rule would work better as...
/s([alnum]+)/? /index.php?s=$1
added: I don't think the second to last rule will ever get invoked either as written.... single character session hashes are probably kind of rare in vbulletin URLs
Ahmad 07-09-2002, 08:10 PM Originally posted by eva2000
well it can have something after the s, since vB also has sessionhashes if you browse using sessions instead of cookies
OK, that is what I expected, and i bet that if you try putting more than one character after the 's' then the rule won't work ;)
In that case you should replace the '?' with a '*'.
|