我试图建立一些重定向和我的.htaccess文件来处理一些旧的论坛网址。我想提出的重定向根据PHP参数(主题ID)。
I'm trying to build some redirections with my .htaccess file to deal with some old forum url. I want the redirections to be made according to the PHP parameters (the topic ID).
例如,像
RewriteEngine On
RedirectPermanent /forum/viewtopic.php?t=123 /page1.html
RedirectPermanent /forum/viewtopic.php?t=345 /page7.html
RedirectPermanent /forum/viewtopic.php?t=89 /page3.html
旧的和新的URL不是彼此相关的(没有PHP的参数必须保持或东西)。我想在我的.htaccess文件中手动决定要怎么做每个主题ID。
The old and new URL are not related to each other (no PHP parameter has to be kept or something). I want to decide manually in my .htaccess file what to do for each topic ID.
但我不能设法做那么容易。我试过很多东西,但没有任何工程。
But I can't manage to do that so easily. I tried many things, but nothing works.
这可能吗?你知道吗?
非常感谢!
编辑:另一个问题:我想所有的文件夹/论坛的全球重定向添加到站点的根目录(/)。我想其他人后,我可以把它,因此,如果没有其他规则trigered,这将是一个trigered。
Edit : additional question : I want to add a global redirection of all the folder /forum to the root of the site ("/"). I guess I can place it after the others, so if no other rule is trigered, this one will be trigered.
我试图像
RewriteRule ^forum /? [L,R=301]
但一切我都试过到目前为止,我重定向到page1.html(我的第一条规则)。知道为什么吗?非常感谢!
But everything I have tried so far redirects me to the "page1.html" (my first rule). Any idea why ? Thanks a lot !
您不能对查询字符串启用mod_alias比赛重定向
, RedirectMatch
,等你需要使用mod_rewrite和比赛反对%{QUERY_STRING}
变量:
You can't match against the query string using mod_alias's Redirect
, RedirectMatch
, etc. You need to use mod_rewrite and match against the %{QUERY_STRING}
variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^t=123$
RewriteRule ^forum/viewtopic.php$ /page1.html? [L,R=301]
RewriteCond %{QUERY_STRING} ^t=345$
RewriteRule ^forum/viewtopic.php$ /page7.html? [L,R=301]
RewriteCond %{QUERY_STRING} ^t=89$
RewriteRule ^forum/viewtopic.php$ /page3.html? [L,R=301]
请注意, RewriteEngine叙述
是一个mod_rewrite的指令,而不是mod_alias中。所以它没有在所有的永久重定向
指令的影响。
NOte that RewriteEngine
is a mod_rewrite directive, not mod_alias. So it has no affect at all on the RedirectPermanent
directives.