By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,286 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,286 IT Pros & Developers. It's quick & easy.

Re: mod_rewrite : redirecting all pages to another set

P: n/a
On Tue, 7 Oct 2008, Grant wrote:
On Mon, 6 Oct 2008 17:58:24 +0200, LC wrote:
>Our institute has a set of apache servers. What we want to do is to put
up a banner with an important announcement,
>RewriteEngine on
Options FollowSymLinks
RewriteRule ^(.*) /~lucio/temp/temp/index.cgi?$1 [L,NS]
>The point is that any url is correctly translated into index.cgi?url
but then the rewritten url is again submitted to translation.

I tried to block the loop putting BEFORE the RewriteRule a
RewriteCond %{REQUEST_URI} !^/\~lucio/temp/temp/index\.cgi

but that causes an HTTP_FORBIDDEN.

How can I force mod_rewrite to rewrite ANY URL as index.cgi?URL with the
exception of index.cgi itself ?

You don't, just map index.cgi -index.cgi?home.html or something, or
use the fake directory cgi option -- lot's of other ways to do this,
perhaps even RTFM? Lots of examples in there.
I carefully RTFM, but can't find an example like my case.

What is the " fake directory cgi option" ?
(in general I avoid using /cgi-bin or personal /user-bin and tend to use
local CGIs in the same directory as the rest of the pages)

What do you mean by " map index.cgi -index.cgi?home.html" ? If
index.cgi is called without arguments, it already provides a default
argument (inside the script).

But this has nothing to do with my issue :

mod_rewrite correctly rewrites ANY_URL as index.cgi?ANY_URL (*)

but then it attempts to rewrite index.cgi itself ! I need a way to stop
this loop

(*) as it should be. The effect of the cgi is to display on one hand a
popup with a banner message, on the other to display the requested
ANY_URL page in the main window
--
----------------------------------------------------------------------
no****@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Oct 7 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"LC's No-Spam Newsreading account" <no****@mi.iasf.cnr.itwrote:
>I carefully RTFM, but can't find an example like my case.
There are four options available to you.

1)
Try various examples you find on the web or in newsgroups
and hope you stumble upon one that does what you want.
Best if what you want is exactly the same as what a bunch
of other people want.

2)
Spend a bunch of time learning mod_rewrite from the ground
up, doing small experiments and doing extensive testing.
Best if you set up websites for a living.

3)
Hire someone with experience to do it for you. If you don't
have any money, get a part time job at McDonald's and use
that money to hire an expert. That will take up less of
your time than doing it yourself will. Best if your time
is worth more than what they pay prisoners.

4)
Give up. Decide that you can live without doing what you
want to do.

Oct 7 '08 #2

P: n/a
On Tue, 7 Oct 2008, in*****@example.org wrote:
There are four options available to you.
1) Try various examples you find on the web or in newsgroups
2) Spend a bunch of time learning mod_rewrite from the ground
3) Hire someone with experience to do it for you. If you don't
4) Give up. Decide that you can live without doing what you
Thanks for the very unhelpful suggestions :-(

After all I found a way to do what I wanted.

The infinite loop in going from url to index.cgi?url was NOT due to the
fact index.cgi is itself an url subject to rewriting ...

.... but to the fact index.cgi does a document.location=url redirection
itself, and therefore causes another rewrite on the target url, and
another, and another.

The way to cut that out was the following :

- I noticed that if I call a page url directly, it has an empty referer
while if I call the page through the CGI, it has a referer equal to
the same page url

- therefore this is what I put in the .htaccess

RewriteCond %{HTTP_REFERER}<->http://%{SERVER_NAME}%{REQUEST_URI} !^(.*)<->\1$
RewriteRule ^(.*).html /~lucio/temp/temp/index.cgi?$1.html [L]

so the rewrite is triggered only if the referer is NOT THE SAME as the
invoked URL.

The condition looks clumsy, because I haven't found a way to test
A==B in a RewriteCond (where both A and B are variables), but to test
that "A concatenated a separator concatenated B" is equal to
"anything concatenated a separator concatenated the same thing" ...

... but I employed the same sort of expression already

(anyhow if anybody has a simpler way of doing such test it will be
definitely welcome)

--
----------------------------------------------------------------------
no****@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
Oct 7 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.