Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have products.php which I'm trying to change into /europe-cell-phone/. I've made a rewrite rule to do this:

RewriteRule ^europe-cell-phone/$ products.php [L]

However I also need to 301 the old page (products.php) to /europe-cell-phone/. I'm trying to do this with the following rule:

RewriteRule ^products.php$ http://www.eurobuzz.com/europe-cell-phone/ [R=301,L]

However of course when I go to products.php expecting to be redirected I hit an infinite redirect loop, is there any solution to this? Never encountered this problem before.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You need to rename your products.php to products-new.php and create two rules like these:

RewriteRule ^europe-cell-phone/$ products-new.php [L]

RewriteRule ^products.php$ products-new.php [R=301,L]

share|improve this answer
    
not the best solution but oh well. –  zuk1 Sep 18 '09 at 11:01
    
Don’t forget to escape the dot. –  Gumbo Sep 18 '09 at 12:31

You need to test the original request in THE_REQUEST as REQUEST_URI already might have been changed by a rule:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /products\.php
RewriteRule ^products\.php$ /europe-cell-phone/ [R=301,L]
RewriteRule ^europe-cell-phone/$ products.php [L]
share|improve this answer

for rewrite in apache, you write them like this: RewriteRule pattern substitution

So the first rule you list matches "europe-cell-phone" and replaces it with "products.php"

Your second rule seems to do the opposite. I think you may need to switch things around in your first rule.

share|improve this answer
    
My first rule means that when I go to domain.com/europe-cell-phone/ it produces the page products.php. –  zuk1 Sep 17 '09 at 15:33
    
(which is what I want) –  zuk1 Sep 17 '09 at 15:34
    
sorry, i'm confused. is URL to products.php domain.com/europe-cell-phone/products.php, or is it domain.com/products.php? –  brad.lane Sep 17 '09 at 15:45
    
I want domain.com/europe-cell-phone/ to display domain.com/products.php, and I want people who go to domain.com/procucts.php to go to domain.com/europe-cell-phone/ –  zuk1 Sep 17 '09 at 15:50
    
make your second rule more specific. when your second rule gets rewritten by apache, it triggers your first, which triggers your second, etc, etc. include domain.com in the pattern of your second rule; not just ^products.php$ –  brad.lane Sep 17 '09 at 16:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.