Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule with query string

Should but doesnt work

         

benjosen

7:27 pm on Oct 15, 2009 (gmt 0)

10+ Year Member



Hi,

I am a bit lost with this rewriterule.

http://www.example.com/index.php?s=3&cat_id=3_Shirts&artikel=3335_55DSL+Andrea+-+Pink+is+Punk&Search_Brand=55DSL&ref=2

should 301 redirect to

http://www.example.com/55dsl-andrea-pink-is-punk.html

I have tried with RewriteCond:
RewriteCond %{QUERY_STRING} ^s=3&cat_id=3_Shirts&artikel=3335_55DSL+Andrea+-+Pink+is+Punk&ref=2$
RewriteRule ^(.*)$ /55dsl-andrea-pink-is-punk.html? [L,R=301]

but it doesn't work. COuld anybody give me some help please. I appreciate it.

jdMorgan

7:53 pm on Oct 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your QUERY_STRING pattern does not contain "Search_Brand=55DSL" and so will not match the URL+query that you say you want to redirect.

Also, the RewriteRule pattern should match "index.php", and not "anything, everything, or nothing" as it does now.

Jim

benjosen

9:42 pm on Oct 15, 2009 (gmt 0)

10+ Year Member



thanks for your help. Just a question why the RewriteRule pattern should match "index.php", and not "anything, everything, or nothing"? I ask because it also works with "anything, everything, or nothing".

jdMorgan

10:06 pm on Oct 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> why the RewriteRule pattern should match "index.php", and not "anything, everything, or nothing"?

Because you said in your statement of requirements in the first post that you wanted to redirect from "index.php" with that specific query string appended to "/" with no query string. Would you want to permanently redirect your robots.txt or sitemap.xml to "/" just because someone tacked a query string onto that URL? Most likely not...

Make your patterns and rules as specific as possible. It's usually better to make them too specific and have to modify them to cast a wider net, than to make them insufficiently specific and have them unexpectedly affect all sort of URL requests.

Jim