Forum Moderators: phranque
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
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]
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]
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
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!
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
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