2011-02-03 88 views
1

如何重定向我的网址 - www.example.com/home.php?rid=888601032动态URL重定向

到www.example.com/examplepage.php

我尝试了好几种htaccess的代码7我新的htccess,我会很感激,如果有人可以给我正确的重定向代码。

回答

1

的语法是:

redirect accessed-file URL-to-go-to 

分为3个部分;

(1) the Redirect command, 
(2) the location of the file/directory you want redirected, and 
(3) the full URL of the location you want that request sent to. 

这些零件由一个空格分开,并应在一行上。

例如,如果要重定向从oldfile.html用户在您的帐户,我的帐户的www目录,以newpage.html,语法应

redirect /~myaccount/oldfile.html http://www.indiana.edu/~myaccount/newpage.html 
1

在YOUT .htaccess文件将这个:

RewriteEngine on 
RewriteBase/
RewriteCond %{QUERY_STRING} rid=888601032 
RewriteRule ^home.php  examplepage.php [R,L,QSA] 

如果您不希望重定向显示,请保留[R]标志。

希望这会有所帮助!

0

会不会更好地使用PHP来做到这一点?

if ((int)$_GET['rid'] == 888601032) // or something like this 
    header('Location: examplepage.php'); 

这取决于你想做的事,但如果你想重定向到一个不同的页面取决于“RID”参数会比较灵活,或者如果你想要做一些操作(比如设置一个cookie)在重定向用户之前。

1

您需要的重定向非常简单。

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(home\.php)?\?rid=888601032\ HTTP/ 
RewriteRule ^(home\.php)?$ http://www.example.com/examplepage.php? [R=301,L] 

它将任何根请求重定向到其中的RID。