2009-06-17 35 views
0

我有一個名爲bfly.php現有頁面,我需要改變蝴蝶jewelry.php.htaccess反向重寫不循環?

我想讓它這樣,如果有人去的URL 蝴蝶jewelry.php他們得到了bfly.php頁面,但url並沒有改變它保持爲butterfly-jewelry.php。但也有人直接去bfly.php的URL更改爲butterfly-jewelry.php

有沒有辦法做到這一點,而不陷入重寫循環?

謝謝!

回答

1

您可以將文件重命名爲例如bfly1.php然後用這個:

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

(我試過Blixt的解決方案,但它造成儘管L-標誌一個無限循環)。

+0

其實我想如果我要改變一個文件的名字,我只會把bfly.php改成butterfly-jewelry.php,然後只是使用答案中的第二行。謝謝! – 2009-06-17 14:56:34

0

可以使用最後一個規則和重定向標誌做你想做的(見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] 

我沒有測試以上,但我相信它應該工作。

+0

謝謝大家,我認爲這是在正確的軌道,但兩者的網址上現在正在帶我去www。 MYDOMAIN。 com/var/www/vhosts/MYDOMAIN.com/httpdocs/butterfly-jewelry.php – 2009-06-17 14:08:20