Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Users

RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc]

 

 

Apache users RSS feed   Index | Next | Previous | View Threaded


sebbaz at gmail

Aug 17, 2012, 5:49 AM

Post #1 of 6 (788 views)
Permalink
RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc]

What's the canonical way to redirect the following?

http://host/xyz[/abc]
to
http://xyz.host/[abc]

The following works

RedirectMatch ^xyz(.*) http://xyz.host$1

but suffers from the problem that

http://host/xyz123

is redirected to

http://xyz.host123

which is not intended.

I suppose one way would be to use a pair of redirects:

RedirectMatch ^xyz http://xyz.host
RedirectMatch ^xyz/(.*) http://xyz.host/$1

but is there a better way?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


covener at gmail

Aug 17, 2012, 7:02 AM

Post #2 of 6 (763 views)
Permalink
Re: RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc] [In reply to]

> The following works
>
> RedirectMatch ^xyz(.*) http://xyz.host$1
>
> but suffers from the problem that
>
> http://host/xyz123

maybe RedirectMatch ^xyz(/.*)? http://xyz.host$1

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


sebbaz at gmail

Aug 17, 2012, 7:23 AM

Post #3 of 6 (758 views)
Permalink
Re: RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc] [In reply to]

On 17 August 2012 15:02, Eric Covener <covener [at] gmail> wrote:
>> The following works
>>
>> RedirectMatch ^xyz(.*) http://xyz.host$1
>>
>> but suffers from the problem that
>>
>> http://host/xyz123
>
> maybe RedirectMatch ^xyz(/.*)? http://xyz.host$1

That won't match

http://host/xyz

which should redirect to

http://xyz.host/

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe [at] httpd
> For additional commands, e-mail: users-help [at] httpd
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


covener at gmail

Aug 17, 2012, 7:30 AM

Post #4 of 6 (769 views)
Permalink
Re: RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc] [In reply to]

>> maybe RedirectMatch ^xyz(/.*)? http://xyz.host$1
>
> That won't match
>
> http://host/xyz

question mark was part of the regex not punctuation, but not sure the
redirect w/o trailing slash is okay.

rejiggered to always have the trailing slash:

RedirectMatch ^xyz/?(.*) http://xyz.host/$1

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


sebbaz at gmail

Aug 17, 2012, 7:58 AM

Post #5 of 6 (763 views)
Permalink
Re: RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc] [In reply to]

On 17 August 2012 15:30, Eric Covener <covener [at] gmail> wrote:
>>> maybe RedirectMatch ^xyz(/.*)? http://xyz.host$1
>>
>> That won't match
>>
>> http://host/xyz
>
> question mark was part of the regex not punctuation,

Very sorry, my bad, I should have read more carefully.

Your suggestion will work fine.

> but not sure the redirect w/o trailing slash is okay.

It's OK if it is a directory.

If xyz is a directory, then without the redirect, http://host/xyz should display

http://host/xyz/index.html

If http://host/xyz is redirected to

http://xyz.host/

This should result in displaying

http://xyz.host/index.html

as intended.

Maybe your solution should be added as an example to the RedirectMatch docs?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd


sebbaz at gmail

Aug 17, 2012, 8:33 AM

Post #6 of 6 (762 views)
Permalink
Re: RedirectMatch - http://host/xyz[/abc] => http://xyz.host/[abc] [In reply to]

On 17 August 2012 15:58, sebb <sebbaz [at] gmail> wrote:
> On 17 August 2012 15:30, Eric Covener <covener [at] gmail> wrote:
>>>> maybe RedirectMatch ^xyz(/.*)? http://xyz.host$1
>>>
>>> That won't match
>>>
>>> http://host/xyz
>>
>> question mark was part of the regex not punctuation,
>
> Very sorry, my bad, I should have read more carefully.
>
> Your suggestion will work fine.

Actually it does have a problem, because it matches
http://host/xyz123
and redirects to
http://xyz.host/
this is because it can match without the trailing context.

So I think one needs to anchor the regex:
RedirectMatch ^xyz(/.*)?$ http://xyz.host$1

That seems to work OK.

Thanks for putting me on the right track.

>> but not sure the redirect w/o trailing slash is okay.
>
> It's OK if it is a directory.
>
> If xyz is a directory, then without the redirect, http://host/xyz should display
>
> http://host/xyz/index.html
>
> If http://host/xyz is redirected to
>
> http://xyz.host/
>
> This should result in displaying
>
> http://xyz.host/index.html
>
> as intended.
>
> Maybe your solution should be added as an example to the RedirectMatch docs?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe [at] httpd
For additional commands, e-mail: users-help [at] httpd

Apache users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.