2016-06-24 21 views
0

我沒有太多的編程知識,所以我想要一些幫助。我想將301 url /viewforum.php?f=19重定向到另一頁。所以想要放入viewform.php來這樣做。我用下面的代碼如何重定向一個不同的PHP頁面

<?php 
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.example.com/"); 
exit(); 
?> 

但它重定向/viewform.php內的一切,但我只是想重定向/viewform.php?f=19

+1

你也可以從[htaccess](https://httpd.apache.org/docs/current/howto/htaccess.html)重定向。 –

+0

正如上面的Ganesh所提到的,你也可以從'.htaccess'重定向,我建議你這樣做,這樣你就可以更容易地看到重定向,並且不必記住你放置不同重定向的位置在不同的文件中。 – Epodax

+0

我希望這個參考鏈接對你有幫助http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php謝謝你! –

回答

1
<?php 
     if($_GET['f']==19) 
     {  
      //header("HTTP/1.1 301 Moved Permanently"); no need 
      header("Location: http://www.example.com/"); 
      exit(); 
     } 
?> 

希望這將有助於