Web Servers on Unix and Linux - Apache rewriteRule -

This is Interesting: Free IT Magazines  
Home > Archive > Web Servers on Unix and Linux > July 2007 > Apache rewriteRule -





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Apache rewriteRule -
kdband@gmail.com

2007-07-17, 1:18 pm

I'm sure this will seem like a really lame question to some of you,
but I just can't work this out today:-

I need a rule which will redirect from :

1. http://my.domain.com/mydir/old_dir/abc/test.jsp
2. http://my.domain.com/mydir/old_dir/def/test1.html
3. http://my.domain.com/mydir/old_dir/...nother_test.jsp

to:

1. http://my.domain.com/mydir/new_dir/abc/test.jsp
2. http://my.domain.com/mydir/new_dir/def/test1.html
3. http://my.domain.com/mydir/new_dir/...nother_test.jsp

i.e. it needs to redirect any occurance of "old_dir" in the URL to
"new_dir". The domain name and "mydir" part will always remain the
same, but the part after the "old_dir" bit could be anything.

I'm not sure if it makes any difference, but I'm doing this in
httpd.conf.

Thanks.

phantom

2007-07-17, 1:18 pm

<kdband@gmail.com> wrote in message
news:1184683402.207599.50510@g12g2000prg.googlegroups.com...
> I'm sure this will seem like a really lame question to some of you,
> but I just can't work this out today:-
>
> I need a rule which will redirect from :
>
> 1. http://my.domain.com/mydir/old_dir/abc/test.jsp
> 2. http://my.domain.com/mydir/old_dir/def/test1.html
> 3. http://my.domain.com/mydir/old_dir/...nother_test.jsp
>
> to:
>
> 1. http://my.domain.com/mydir/new_dir/abc/test.jsp
> 2. http://my.domain.com/mydir/new_dir/def/test1.html
> 3. http://my.domain.com/mydir/new_dir/...nother_test.jsp
>
> i.e. it needs to redirect any occurance of "old_dir" in the URL to
> "new_dir". The domain name and "mydir" part will always remain the
> same, but the part after the "old_dir" bit could be anything.
>
> I'm not sure if it makes any difference, but I'm doing this in
> httpd.conf.
>


RewriteRule ^/mydir/old_dir/(.*)$ http://my.domain.com/mydir/new_dir/$1
[R=301]

should do the trick.


Nick Kew

2007-07-17, 7:18 pm

On Tue, 17 Jul 2007 07:43:22 -0700
kdband@gmail.com wrote:

> I'm sure this will seem like a really lame question to some of you,
> but I just can't work this out today:-


Forget Rewriterule. It's much more complex than you need.

If it's important to update the URL, use Redirect.
If it's just internal and the URL doesn't matter, use Alias.

--
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com