【问题标题】:301 Redirect showthread.php?t=1&page=2 to threads/1/page-2?301 重定向showthread.php?t=1&page=2 到threads/1/page-2?
【发布时间】:2014-12-02 21:30:18
【问题描述】:

我想重定向以下内容

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

请指教?

【问题讨论】:

  • 你尝试了什么,你在哪里卡住了?

标签: .htaccess redirect


【解决方案1】:

你可以使用:

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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2013-12-14
    • 2017-02-15
    • 2023-01-11
    • 2018-10-21
    • 1970-01-01
    • 2019-05-03
    相关资源
    最近更新 更多