views:

216

answers:

2

I have an existing page called bfly.php that I need to change to butterfly-jewelry.php

I want to make it so that if someone goes to the URL butterfly-jewelry.php they get the bfly.php page but the url doesn't change it stays as butterfly-jewelry.php. BUT also if someone goes directly to bfly.php the url changes to butterfly-jewelry.php

Is there a way to do this without getting stuck in a rewrite loop?

Thanks!

A: 

You can use the Last Rule and Redirect flags to do what you want (see the mod_rewrite documentation):

# Rewrite request to bfly.php, and then stop the rewrite engine.
RewriteRule ^butterfly-jewelry\.php$ bfly.php [L]
# Redirect the client to butterfly-jewelry.php with "Permanently Moved" status
RewriteRule ^bfly\.php$ butterfly-jewelry.php [L,R=301]

I haven't tested the above, but I believe it should work.

Blixt
Thank you I think this is on the right track but both urls are now taking me to www. MYDOMAIN. com/var/www/vhosts/MYDOMAIN.com/httpdocs/butterfly-jewelry.php
John Isaacks
+1  A: 

You could rename the file to e.g. bfly1.php and then use this:

RewriteRule ^butterfly-jewelry\.php bfly1.php [L,QSA]
RewriteRule ^bfly\.php http://yourhost.com/butterfly-jewelry.php [L,QSA,R=301]

(I tried Blixt's solution, but it caused an infinite loop despite the L-flag.)

Uqqeli
Actually I figured if I was going to change the name of a file I would just change bfly.php to butterfly-jewelry.php and then just use the second line from your answer. Thanks!
John Isaacks