Forum Moderators: phranque

Message Too Old, No Replies

Tricky Rewrite Rule

         

benjosen

7:59 pm on Oct 28, 2009 (gmt 0)

10+ Year Member


Hi,
I have posted this on a German forum but nobody could yet help me and it is quite urgent. So all my hope is for you ;[smilestopper])

I have the following problem:

URL old:
http://www.mydomain.de/index.php?s=2&Search_Brand=BRAND

URL new:
http://www.mydomain.de/brand

I made Conds and Rules – these are working just fine, e.g.:

RewriteCond %{QUERY_STRING} ^s=2&Search_Brand=BRAND$
RewriteRule ^(.*)$ /brand? [L,R=301]

These are special pages that have a new target URL. Besides those "important" ones the other URLs with /index.php?s=...., should all be redirected to the startpage.
So I want special rules for some URLs and the "rest" should be redirected to the startpage.

There is the rule I put at the end of all other rules:
RewriteRule ^index\.php$ http://www.mydomain.de/? [R=301,L]

It works just fine but now the special rules (see above) do not work anymore (even with [R=301,L]) and are also redirected to the startpage.

Anyone has a clue? I appreciate it.

g1smd

8:18 pm on Oct 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to check that a request for old URLs is a direct client request.

Check THE_REQUEST using a preceding RewriteCond. Additionally add the canonical domain to the target URL of that redirect.

There's a large number of prior examples here in this forum.

benjosen

9:16 pm on Oct 28, 2009 (gmt 0)

10+ Year Member



Thanks a lot for your answer. Looks like it is working properly now.

benjosen

7:27 am on Oct 29, 2009 (gmt 0)

10+ Year Member


Obviously I was a bit to quick being happy ...

I am not sure if I got it right:
RewriteCond %{QUERY_STRING} ^s=2&Search_Brand=BRAND$
RewriteRule ^(.*)$ http://www.mydomain.de/brand? [L,R=301]

but how do I check THE_REQUEST? Do I need to add another RewriteCond %{THE_REQUEST} - but what to put there?

I have checked the forum but could not find a solution for my particular problem.

jdMorgan

3:39 pm on Oct 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the correct "structure," if not correct in every detail of RewriteCond and RewriteRule patterns:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(#[^?&\ ]*)?\?([^&\ ]*&)?s=2&Search_Brand=([^&\ ]+)[^\ ]*\ HTTP/
RewriteRule ^index\.php http://www.example.com/%3? [R=301,L]

If you have trouble, please be very specific about the problem:
  • How did you test? (What URL did you type?)
  • What did you expect to happen?
  • What were the actual results?
  • How did actual results differ from your expectations?
  • Any browser messages?
  • Any relevant error messages in the server error log?
  • Any relevant information in the server access log?

    Jim

  •