You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Mattison, Jacob" <JM...@uarts.edu> on 2004/01/07 17:24:18 UTC

[users@httpd] RedirectMatch question

(and also, I suppose, a regular expression question)

I want to insert a RedirectMatch directive for apache that will allow someone to view the index page (and possibly, later, other specified pages) on port 80, but will redirect any other page request on port 80 to the equivalent address on port 443.

(So that the non-ssl index page can have helpful tips about how to make sure your browser supports 128-bit encryption and such).

So if the url is "http://mysite.domain.edu/index.html", it should serve it (i.e. RedirectMatch shouldn't match), but for 
"http://mysite.domain.edu/foo/bar/hello.html" it should redirect to "https://mysite.domain.edu/foo/bar/hello.html".

(Note: ideally "http://mysite.domain.edu" by itself shouldn't match either, since it's functionally equivalent to "http://mysite.domain.edu/index.html" in this case.)

The part I'm mainly stuck on, I guess, is constructing a regular expression that will match [everything except "index.html"].  But I thought someone else might possibly have done something like this and have the directive handy.

Thanks for any help!

Jacob Mattison
Web Administrator
University of the Arts

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] RedirectMatch question

Posted by Robert Andersson <ro...@profundis.nu>.
Mattison, Jacob wrote:
> So if the url is "http://mysite.domain.edu/index.html", it should serve
> it (i.e. RedirectMatch shouldn't match), but for
> "http://mysite.domain.edu/foo/bar/hello.html" it should redirect to
> "https://mysite.domain.edu/foo/bar/hello.html".

I think this pattern would do (requires Apache 2.0):

    RedirectMatch ^/((?<!index\.html).+) https://securehost/$1

It will match a / followed by something, but not "index.html", using a
negative look-behind assertion. I'm rusty, so I'm not certain that it will
work. It makes use of PCRE, which is supported by Apache 2.0.xx, but not
1.3. Interesting reading:

    http://www.perldoc.com/perl5.8.0/pod/perlre.html

You could also do this with mod_rewrite (untested):

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/(index\.html)?$
    RewriteRule (.*) http://securehost/$1 [R]

Regards,
Robert Andersson


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org