Forum Moderators: phranque

Message Too Old, No Replies

New to Apache url rewriting

         

Parasite jimmy

10:37 am on Sep 15, 2006 (gmt 0)

10+ Year Member



Can someone help?

I'm trying to redirect the following url

http://www.example.com/app/sfd/cat/pro.jsp?cId=A331831&id=42251

to

http://www.example.com/app/sfd/cat/home.jsp

Im using apache 2.0.55
I've tried examples like this with little success.

Redirect /app/sfd/cat/pro.jsp?cId=101156&id=72480 http://www.example.com/app/sfd/cat/home.jsp

jdMorgan

3:51 pm on Sep 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Parasite Jimmy,

Welcome to WebmasterWorld!

You might want to try using mod_rewrite instead of mod_alias to handle query strings attached to URLs.

In your Web root ("home page" directory) .htaccess file:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cId=A331831&id=42251$
RewriteRule ^app/sfd/cat/pro\.jsp$ http://www.example.com/app/sfd/cat/home.jsp? [R=301,L]

Or alternatively, in .htaccess in the /app/sfd/cat subdirectory:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^cId=A331831&id=42251$
RewriteRule ^pro\.jsp$ http://www.example.com/app/sfd/cat/home.jsp? [R=301,L]

Putting the code in your Web root allows for centralized, and therefore easier, administration. Putting it into the subdirectory means it will be executed far less often and therefore will be more efficient. Your choice, basically.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

Parasite jimmy

9:09 am on Sep 19, 2006 (gmt 0)

10+ Year Member



Thank for you help Jim, I managed to get this to work. I noticed that the redirect worked but the url in the address bar stayed the same, it didnt show the redirected url? Is it possible to get the redirected url in the address bar?

Also, what would you suggest if I had many variations of the query string (ie differnt cId and Id numbers) that also needed to be redirected to the same url?

Thanks for you help!

windspinner

9:14 am on Sep 19, 2006 (gmt 0)

10+ Year Member



I am curious, what does [R=301, L] mean?

jdMorgan

2:10 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PJ,

The code above invokes an external redirect response, which will force the client (browser) to re-request the desired page content from the new URL given in the redirect response. This will update the address bar, unless...

The only way to stop the address bar from being updated is if the page is framed. This would either be something you're aware of -- if your page is coded using frames, or it may be a result of "domain forwarding" using frames -- something I cannot recommend if you're serious about using advanced server features and/or achieving solid search rankings for your site.

If you're not sure do a View Page Source in your browser, to see if your page is being framed.

Jim

Parasite jimmy

3:22 pm on Sep 19, 2006 (gmt 0)

10+ Year Member



No the website isnt using frames

Must have been an error on my part as it seems to be working fine now with the redirected url appearing in the address bar.

Thanks Jim

jdMorgan

10:58 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PJ,

OK, probably this: You must flush your browser cache (Temporary Internet Files) for IE before testing any new
configuration changes.

Windspinner,

The [R=301,L] flags, in conjunction with a canonical URL in the RewriteRule substitution, specifies that the server should return a 301 redirect response to the client, giving it the substitution URL so that it can re-request the desired resource, and that mod_rewrite processing should terminate at this point: [L] means "last rule" (but only if this rule matches).

Jim