Forum Moderators: phranque

Message Too Old, No Replies

question mark in rewriterule

question mark in rewriterule

         

gonen

7:08 am on Dec 23, 2004 (gmt 0)

10+ Year Member



I am running an Apache web server, and trying to create a rewrite rule.
The structure of the page users will navigate to is:
(*).cgi?forum=1000&(*)

The "*" , as in regular expression, means "whatever".

I created the following rewrite rule:
RewriteRule ^/((.*)+(\.)+(cgi)+(=)+(forum)+(=)+(1000)+(&))+(.*) /index.html

This rule works when I enter address like this:
[localhost...]

My problem is that the “=” sign that is located after "cgi" should be "?",
But when I change it to "?" Inside the brackets I get an error while trying to restart Apache service.
I also tried it in the following syntax: (\?) but it doesn’t seem to work either.

I can't leave the rule as it is now because CGI requires a "?" before the variables.

I suppose that there is a solution to my problem, I just couldn't find it.

Please tell me, what is the right syntax for this kind of rule.

Thank you,

Gonen radai

[edited by: jdMorgan at 5:29 pm (utc) on Dec. 23, 2004]
[edit reason] No sigs, please. See TOS. [/edit]

incywincy

7:58 am on Dec 23, 2004 (gmt 0)

10+ Year Member



probably not the most elegant solution but would this work?

RewriteRule ^/((.*)+(\.)+(cgi)+(.forum)+(=)+(1000)+(&))+(.*) /index.html

ie replace? with wildcard .

gonen

8:23 am on Dec 23, 2004 (gmt 0)

10+ Year Member



well,
i took your rule (that didnt work)
RewriteRule ^/((.*)+(\.)+(cgi)+(.forum)+(=)+(1000)+(&))+(.*) /index.html

and added \ before the . like that:
RewriteRule ^/((.*)+(\.)+(cgi)+(\.forum)+(=)+(1000)+(&))+(.*) /index.html

now when i enter the following address:
[localhost...]

i do get the right redirection, but i dont know if the wildcard . can replace? in CGI. can it?

jdMorgan

5:29 pm on Dec 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



gonen,

Welcome to WebmasterWorld!

I suspect you're going about this process backwards, as it's far more usual to rewrite from a static URL to a dynamic URL with a query string.

If you do wish to rewrite from a dynamic URL to a static URL, you will have to handle the query string separately, since it is not part of a URL, but rather, data to be passed to the resource at that URL. See mod_rewrite's RewriteCond [httpd.apache.org] directive, and use the %{QUERY_STRING} server variable to capture, test, and create back-references to your query data.

Jim

gonen

7:00 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



thanks for your comment jim,
actually, my redirection is from a dynamic URL to a dynamic URL.

i'll describe the problem further, so you might understand better, and be able to give me the best answer for my case:

i have a set of forums. some are free, others payed subscription on month/year basis.
when my main server is down (for any reason) i want the subscribers to be redirected to the backup server, and the rest (free forums) to get an ERROR PAGE or 404 or whatever. actually my main concern is the subscribers.

so if i have a dynamic address to:
www.mysite.com/somepage.cgi?forum=###&other-variables
i thought of creating rewrite rules (even if i'm talking about 100 rules)
that each one has the specific payed forum number, and redirect it to, let say, address like that:
backup.mysite.com/somepage.cgi?forum=###&other-variables

is rewriterule good for me?
do i need rewrite cond?
what would be the best solution for the situation?

thank you very much.
gonen.

jdMorgan

8:20 pm on Dec 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> when my main server is down (for any reason) i want the subscribers to be redirected

If your main server is down, you can't redirect from it. Instead, you'd want to go change your DNS to point to the backup server. Set a short TTL (Time To Live) on these DNS entries, so that when you change the DNS, it will be picked up more quickly by the non-authoritative DNS servers.

If I miss your meaning about "server is down," and you mean it's in some state where it can still respond to some requests, then you can use RewriteCond %{QUERY_STRING} to match whatever forum numbers you want to forward to the other domain.

Jim

gonen

9:12 am on Dec 24, 2004 (gmt 0)

10+ Year Member



let's focus on the second situation you offer for now,

rewrite cond %{query string}, how do i implement this
using the following general syntax:

www.mysite.com/cgi-bin/forumsdb/intraforum_db.cgi?forum=2&read=&alias=dbr&redir_flag=

where the relevant string is :".cgi?forum=###&"
i don't care what comes before the .cgi
i don't care what comes after the &
and the ### could be different, not a range between 3-10 for example, but 43, 52, 88, 1005, 2039 and so on...

how should i write it?

thanks

jdMorgan

3:07 pm on Dec 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> where the relevant string is :".cgi?forum=###&"

RewriteCond %{QUERY_STRING} ^\.cgi?forum=###&$

> i don't care what comes before the .cgi

RewriteCond %{QUERY_STRING} \.cgi?forum=###&$

> i don't care what comes after the &

RewriteCond %{QUERY_STRING} \.cgi?forum=###&

> and the ### could be different, not a range between 3-10 for example, but 43, 52, 88, 1005, 2039 and so on...

RewriteCond %{QUERY_STRING} \.cgi?forum=([0-9])+&

You will then back-reference the forum number using the variable "%1" in the RewriteRule (in order to "copy" it into the new URL-path).

Please read our forum charter [webmasterworld.com] for more information.

Jim

gonen

12:40 pm on Dec 25, 2004 (gmt 0)

10+ Year Member



thank you very much.
i solved my problem with your help...

thanks again

gonen.