2015-06-14 57 views
0

舊的URL是這樣的: http://mywebsite.com/index.php?mode=thread&id=284607如何使用參數重定向動態網址?

新的網址是: http://mywebsite.com/threads/284607

正如你所看到的,我想從舊的動態URL抓取編號,並將其指向新漂亮的網址。

我試過在這裏和其他地方找到解決方案,但不斷從重定向中刪除「mode = thread」部分的問題。

感謝您的幫助!

更新:下面是一些已經在.htaccess文件中的其他代碼。

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

回答

0

在.htaccess文件:

RewriteEngine On 
RewriteCond %{QUERY_STRING} ^mode=thread 
RewriteCond %{QUERY_STRING} &id=([0-9]+) 
RewriteRule ^index\.php$ /threads/%1? [L,R=301] 
+0

謝謝你的快速響應!它現在重定向到:http://mywebsite.com/?mode=thread&id=284607 – Wendell

+0

是的,這就是你想要的不是嗎? – xcvd

+0

不,它需要去http://mywebsite.com/threads/284607 – Wendell

2

很多谷歌搜索後,我發現這工作:

RewriteCond %{QUERY_STRING} (^|\?)mode=thread&id=([0-9]+)($|&) 
RewriteRule ^index\.php$ http://mywebsite.com/threads/%2/? [R=301,L] 
相關問題