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

时间:2014-12-02 11:09:57

标签: .htaccess redirect

我想重定向以下

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重定向到文件夹结构。

请指教?

1 个答案:

答案 0 :(得分: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]