Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

apache 2.2.22 mod_rewrite RewriteCond

34 views
Skip to first unread message

michael....@wesustain.com

unread,
Apr 23, 2013, 10:08:22 AM4/23/13
to
Hi,
I want do do a (stupid) redirection and I'm stuck.

Redirection shoud look like this

http://some_url.org -> http://some_other_url.org
but
http://some_url.org/anything -> https://some_url.org/anything

I did several experiments with RewriteCond, RewriteRule, RedirectMatch but I'm stuck. Does anybody have an idea?

Oh, btw this shoud be done by the vhost-config, not with .htaccess-files in document-folders. It's a restriction I'm not responsible for... :-(

thanks a lot

regards M.

michael....@wesustain.com

unread,
Apr 24, 2013, 3:38:19 AM4/24/13
to
Sorry, my initial description was to short.

What I need to do is, to do two redirects on one base-url with two different conditions. First is to redirect a request with just the base-url (like _http://some_url.org) to _http://some_other_url.org .

_http://some_url.org -> _http://some_other_url.org

The second one is, if _http://some_url.org/some_subdir is requested it shoud be redirected to SSL of the same host _https://some_url.org/some_subdir .
So in case 2 it should not be redirected to some_other_url.org .

_http://some_url.org/some_subdir -> https_://some_url.org/some_subdir

Both rewrites are not verry complex for its own, but I can't get them working together.
So my problem is, how do I have to set the RewriteCond (to be exact the regexp) to do the matching. The http->https overrules always.

I did several experiments with RewriteCond, RewriteRule, RedirectMatch but I didn't get it. Does anybody have an idea?

Oh, btw this should be done by the vhost-config, not with .htaccess-files in document-folders. It's a restriction I'm not responsible for :-( cause developers sometimes empty the doc-folders.

Sorry, I had to do this _http because of this editor to not recognize this "URLs".
thanks a lot

best regards, M.

Jim

unread,
Apr 24, 2013, 2:06:22 PM4/24/13
to
I think this should work (untested). These config lines assume the
context of the VirtualHost for some_url.org:

RewriteRule ^/$ http://some_other_url.org [R=permanent,L,NS]

RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^/(.*) https://some_url.org/$1 [R=permanent,L,NS]

Note: I use RewriteRules for each so there is no question of which
directive is processed first. The directives need to be in this order.
The flag for permanent redirection is up to you. It will send a 301
status with the redirect instead of a 302.

HTH,
Jim

michael....@wesustain.com

unread,
Apr 25, 2013, 3:01:29 AM4/25/13
to
Am Mittwoch, 24. April 2013 20:06:22 UTC+2 schrieb Jim:
>
> RewriteRule ^/$ http://some_other_url.org [R=permanent,L,NS]
>
>
>
> RewriteCond %{HTTPS} !=on [NC]
>
> RewriteRule ^/(.*) https://some_url.org/$1 [R=permanent,L,NS]
>

PERFECT! Thanks a lot Jim.
This exactly solves my Problem.

Best regards, M.

Ruben Safir

unread,
Jun 3, 2013, 6:23:54 PM6/3/13
to
michael....@wesustain.com wrote:
> Sorry, my initial description was to short.
>
> What I need to do is, to do two redirects on one base-url with two different conditions. First is to redirect a request with just the base-url (like _http://some_url.org) to _http://some_other_url.org .
>
> _http://some_url.org -> _http://some_other_url.org
>
> The second one is, if _http://some_url.org/some_subdir is requested it shoud be redirected to SSL of the same host _https://some_url.org/some_subdir .
> So in case 2 it should not be redirected to some_other_url.org .
>
> _http://some_url.org/some_subdir -> https_://some_url.org/some_subdir
>

this is a simple url redictions where you specifiy the post.

But why? Why not just attach the ssl to the url. People do strange
things.

> Both rewrites are not verry complex for its own, but I can't get them working together.
> So my problem is, how do I have to set the RewriteCond (to be exact the regexp) to do the matching. The http->https overrules always.
>
> I did several experiments with RewriteCond, RewriteRule, RedirectMatch but I didn't get it. Does anybody have an idea?
>
> Oh, btw this should be done by the vhost-config, not with .htaccess-files in document-folders. It's a restriction I'm not responsible for :-( cause developers sometimes empty the doc-folders.

Why would anyone want to do this using an .htaccess file? I turn those
things off. They are a huge security risk.

0 new messages