使用参数值重定向到新页面

时间:2013-03-31 10:55:14

标签: wordpress .htaccess redirect

我正在开发wordpress,并希望以某种方式实现重定向,如果有人想要使用任何ID访问该网址:

http://www.example.com/123456789

将被重定向到

http://www.example.com/search.php?id=123456789

我知道如何实现这一目标?我相信我必须使用.htaccess文件,但任何帮助都将受到高度赞赏..

编辑 .htaccess中的标准规则是

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>

# END WordPress

1 个答案:

答案 0 :(得分:1)

您可以尝试使用以下内容替换问题中的规则集:

# BEGIN Wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]

# Add this line
RewriteCond %{REQUEST_URI}    !/document         [NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]

# Add these lines
RewriteCond %{REQUEST_URI}  !search\.php         [NC]
RewriteCond %{REQUEST_URI}  /document/([^/]+)/?  [NC]
RewriteRule .*  /wordpress/search.php?id=%1      [L,NC]

</IfModule>
# END Wordpress

最后一条规则静默映射:

http://localhost/wordpress/document/123

要:

http://localhost/wordpress/search.php?id=123

其中123是动态字符串。

对于永久重定向,用[R = 301,L,NC]替换最后的[L,NC]。