Mod Rewrite / 301 Redirect Help

  • mollyhunter
  • Born
  • Born
  • User avatar
  • Posts: 1

Post 3+ Months Ago

Hi All

I am using mod rewrite to make a URL seo friendly, the code looks like this:

Code: [ Select ]
RewriteRule ^Testing-Instruments.html$ /cgi-bin/ab_page(dot)pl?ref=3.6


I now want to 301 redirect the old dynamic URL to the SEO friendly one but it's creating some kind of loop and isn't working, the code I tried is:

Code: [ Select ]
RewriteCond %{QUERY_STRING} ^ref=3.6$
RewriteRule ^cgi-bin/ab_page\.pl$ http://www.domain(dot)co(dot)uk/Testing-Instruments.html? [R=301,L]
  1. RewriteCond %{QUERY_STRING} ^ref=3.6$
  2. RewriteRule ^cgi-bin/ab_page\.pl$ http://www.domain(dot)co(dot)uk/Testing-Instruments.html? [R=301,L]


I've searched forums and found a command called {THE_REQUEST} which I think may be the answer, but cannot figure out how to implement it to make it work.

Does anyone have any ideas?

Have had to replace . with (dot) as it says i'm not allowed to post external URLs on this board.

Molly
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • PolishHurricane
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1585

Post 3+ Months Ago

What does your whole mod_rewrite configuration look like in order? I'm no pro with mod_rewrite, but what it looks like you need to do is, redirect old references to the new one first... So anything with ^ref=3.6 redirects to the new rule first, THEN redirect Testing-Instruments.html calls. If you do it the other way around, you will be converting the new calls to refs, then the refs to new calls, then it will infinite loop.

So something like this (this is just reusing your code in different order, don't know if it'll work):

Code: [ Select ]
RewriteCond %{QUERY_STRING} ^ref=3.6$
RewriteRule ^cgi-bin/ab_page\.pl$ http://www.domain(dot)co(dot)uk/Testing-Instruments.html? [R=301,L]
#Do this after
RewriteRule ^Testing-Instruments.html$ /cgi-bin/ab_page(dot)pl?ref=3.6
  1. RewriteCond %{QUERY_STRING} ^ref=3.6$
  2. RewriteRule ^cgi-bin/ab_page\.pl$ http://www.domain(dot)co(dot)uk/Testing-Instruments.html? [R=301,L]
  3. #Do this after
  4. RewriteRule ^Testing-Instruments.html$ /cgi-bin/ab_page(dot)pl?ref=3.6


Anyway, the variable you're looking for I think is %{REQUEST_URI}, so something like...
Code: [ Select ]
RewriteCond %{REQUEST_URI} ^(.*)ref=3.6(.*)$
RewriteRule ^cgi-bin/ab_page\.pl$ http://www.domain(dot)co(dot)uk/Testing-Instruments.html? [R=301,L]
  1. RewriteCond %{REQUEST_URI} ^(.*)ref=3.6(.*)$
  2. RewriteRule ^cgi-bin/ab_page\.pl$ http://www.domain(dot)co(dot)uk/Testing-Instruments.html? [R=301,L]

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 122 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.