Tux

...making Linux just a little more fun!

Apache -- Redirect if found this "Regex"

Smile Maker [britto_can at yahoo.com]


Thu, 19 Jun 2008 04:05:20 -0700 (PDT)

Folks:

I have recently upgraded all of my jsp's to php's and pointed my rr to the new server. But for the backward compatibility How do i say to apache "if it finds request for any "jsp " go to this php page"

-- 
Britto


Top    Back


Thomas Bonham [thomasbonham at bonhamlinux.org]


Thu, 19 Jun 2008 04:56:43 -0700

Smile Maker wrote:

> Folks:
>
> I  have recently upgraded all of my jsp's to php's and pointed my rr 
> to the new server.But for the  backward compatibility How do i  say to 
> apache "if it finds request for any "jsp "  go to this php page"
>
Try something like this line here.

Redirect 301 /howto.jsp http://yourdomain.org/howto/index.php

Just create a new file in your conf.d directory(redirect.conf is what I use) put your information in it and then just restart apache.

Thomas


Top    Back


Smile Maker [britto_can at yahoo.com]


Thu, 19 Jun 2008 06:24:05 -0700 (PDT)

This example works

Thanks Thomas

-- Britto


Top    Back


Smile Maker [britto_can at yahoo.com]


Thu, 19 Jun 2008 06:46:42 -0700 (PDT)

But for all jsp files to be redirected do it need to do anything with

"FilesMatch " Directive

-- 
Britto


Top    Back


Will [will at willstuff.net]


Thu, 19 Jun 2008 09:56:00 -0400

I can think of two ways off the top of my head:

-create symlinks with a loop that will link the "old" .jsp files to the new .php files

-use mod_rewrite:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.jsp$ $1.php [nc]
This will rewrite any requests for *.jsp to the equivalent *.php.

I hope this helps.

-Will


Top    Back


Smile Maker [britto_can at yahoo.com]


Thu, 19 Jun 2008 06:59:59 -0700 (PDT)

The path of previous jsp files may not match to the current php files path.

So it might through 404 , am i right


Top    Back


Francis Daly [francis at daoine.org]


Thu, 19 Jun 2008 17:13:07 +0100

On Thu, Jun 19, 2008 at 06:59:59AM -0700, Smile Maker wrote:

Hi there,

> The path of previous jsp files may not match to the current php files path.
> 
> So it might through 404 , am i right 

Comparing this with your original mail:

> I have recently upgraded all of my jsp's to php's and pointed my rr
> to the new server.But for the backward compatibility How do i say to
> apache "if it finds request for any "jsp " go to this php page"

...it turns out that the right answer depends on what you actually want to do. Once you've got that clear in your head, the path to the answer will probably be more obvious.

As a first guess, if you mean "when the client requests any url ending in .jsp, ask the client instead to request one specific url /this.php instead", then in the manual where you read about the Redirect already mentioned, look down a bit further for RedirectMatch. Something like

RedirectMatch \.jsp$ http://www.example.net/this.php

might do. But that probably isn't what you wanted, based on the follow-up emails.

As a next guess, if you mean "when the client requests any url ending in .jsp, ask the client instead to request another url which can be derived from the original one", then you probably still want to use RedirectMatch, but this time include the grouping parentheses.

If you have a consistent layout across the old and the new servers, this might work for you.

A more complicated example would be if you mean "when the client requests one of these specific urls, ask the client instead to request a different url, where the mapping from old to new is defined over there". In that case your best bet is probably to look for RewriteMap in the mod_rewrite manuals.

With a complete list of old jsp urls and equivalent new php urls, you could try the RewriteMap thing in combination with "internal redirects", so that instead of asking the client to make a new request of a new url, you return the content that the new request would have returned directly. It's easy to do that wrong, though, so an explicit redirect is probably the way to go.

And also, although this one is probably also not directly useful in your case, there's no reason why a PHP script needs to be accessed at a url that ends ".php". To avoid breaking old urls, you could configure your new apache to process urls that end in ".jsp" by sending the associated file through the PHP processor.

Oh, and stealing a .sig that is relevant here:

A: It reverses the normal flow of conversation. 
Q: What's wrong with top-posting? 
A: Top-posting. 
Q: What's the biggest scourge on plain text email discussions?

Please don't.

f

-- 
Francis Daly        francis@daoine.org


Top    Back


Smile Maker [britto_can at yahoo.com]


Thu, 19 Jun 2008 23:13:03 -0700 (PDT)

My case was your first guess !

Thanks you francis and folks.

-- 
Britto


Top    Back