2016-09-14 80 views
0

我有一個像我想重定向和重寫我的網址

http://www.mywebsite.com/shop-single-full.php?img=35 

我想重寫和重定向這個網址像

http://www.mywebsite.com/Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html 

,其中文本是產品名稱的URL。 我也想,當有人要訪問

http://www.mywebsite.com/shop-single-full.php?img=35 

它會自動重定向它

http://www.mywebsite.com/Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html 

不管我曾嘗試是

RewriteRule ^shop-single-full/?$ ([A-Za-z0-9_\-]+)\-([0-9]+).html?%1 [R,L] 
RewriteRule ^([A-Za-z0-9_\-]+)\-([0-9]+).html?$ /shop-single-full.php?img=$2&name=$1 

,但有一些問題redirection.Thanks

+0

將不同的IMG的ID有不同的URL名稱?像'?img = 10 =>/some_product-10.html','?img = 20 =>/another_product-20.html'?在這種情況下,您需要在代碼中執行此操作,而不是重寫,因爲您需要以某種方式通過ID來獲取名稱。除非你想在你的重寫規則中定義它們? –

+0

Btw ..你說......「我也想......」然後你再次解釋完全一樣的東西? –

+0

@MagnusEriksson這是不同的彼此。如果有人試圖打開醜陋的網址,它不應該打開並重定向到漂亮的網址。(我在說的情況下,URL重寫已完成,但不重定向) –

回答

0

使用header()shop-single-full.php

header("Location: http://www.mywebsite.com/Pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html"); 

瞭解更多關於header()here

+0

我只想阻止/ pure-Copper-Embossed-Jug-amp-4-Steel-Copper-Glass-Set-35.html htaccess中的/shop-single-full.php我該怎麼做? –