Forum Moderators: phranque

Message Too Old, No Replies

Can someone help me please ?

Apache rule

         

razah

10:42 am on Apr 11, 2011 (gmt 0)

10+ Year Member



Hi

I am a real newbie to apache and need a bit of help

I was hoping someone could help me with an apache
rewrite rule - i have been trying to find an answer for days but don't
seem to be having much luck

Basically I have a site (oldsite.com) whenever someody hits a certain
page, which has a URI and query string I want to redirect them to a
newsite (newsite.com). My problem is that it redirects to the new
site ok but it appends the query string to then end of the URL - i
don't want this to happen - just redirect to the requested page. I
have attached my rule below.


RewriteCond %{REQUEST_URI} ^/site/site.do$
RewriteCond %{QUERY_STRING} !XYZ
RewriteRule ^.*$ [newsited.com...]


I hope someone can help

Thanks

Raz

jdMorgan

10:43 pm on Apr 14, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{QUERY_STRING} ^([^&]*&)*abc=XYZ(&.*)?$
RewriteRule ^site/site\.do$ http://newsite.com/new/new.html? [R=301,L]

Appending the "?" operator to the end of the substitution URL will clear the query string. This question mark will NOT appear in the redirected-to URL itself.

The change to the RewriteCond %{QUERY_STRING} pattern assumes that you want to redirect any request with any query string containing the exact name/value pair abc=XYZ. Your original example was a negative match, att odds with your description (as I read it). However, the corrections in the RewriteRule are what is important here.

The first RewriteCond was redundant, in that you can test the URL-path using RewriteRule (after removing its leading slash if this code goes into .htaccess), so that RewritecCond isn't needed.

Jim