我想重定向以下
http://www.example.com/showthread.php?t=1&page=2
至http://www.example.com/threads/1/page-2
和
http://www.example.com/showthread.php?t=1
至http://www.example.com/threads/1
我想" 301重定向"它不是"重写"即我想要" http://www.example.com/showthread.php?t=1&page=2"链接到301重定向到文件夹结构。
请指教?
答案 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]