2014-12-02 102 views
-2

我想重定向以下301将showthread.php?t = 1&page = 2重定向到threads/1/page-2?

http://www.example.com/showthread.php?t=1&page=2http://www.example.com/threads/1/page-2

http://www.example.com/showthread.php?t=1http://www.example.com/threads/1

我想 “301重定向” 它不是 “重写”,即我想要的 “http://www.example.com/showthread.php?t=1&page=2”链接到301重定向到文件夹结构。

请指教?

+0

那你试试,你在哪里卡住? – Novocaine 2014-12-02 11:12:54

回答

0

您可以使用:

RewriteEngine on 
RewriteBase/

# external redirect from actual URL to pretty one 
RewriteCond %{THE_REQUEST} \s/+showthread\.php\?t=(\d+)&page=(\d+) [NC] 
RewriteRule^/threads/%1/page-%2? [R=301,L,NE] 
RewriteCond %{THE_REQUEST} \s/+showthread\.php\?t=(\d+) [NC] 
RewriteRule^/threads/%1? [R=301,L,NE] 

# not for file or directory 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

# internal forward from pretty URL to actual one 
RewriteRule ^threads/(\d+)/page-(\d+)/?$ /showthread.php?t=$1&page=$2 [L,NC] 
RewriteRule ^threads/(\d+)/?$ /showthread.php?t=$1 [L,NC]