[英]Redirect users to Long URL
我有一個應用程序,重寫后的URL像這樣
一個示例鏈接是
可以,但是我需要在網址中包含產品的標題
http://storeiown.com/product/a-very-nice-electric-cooker-by-kitchenking/92013
我也做到了,一切都很好。
現在,我希望所有不包含標題的網址都重定向到此網址。 就像,如果用戶從沒有標題的url登陸,則應將他們重定向到頁面的版本,該URL包含url中的標題。
我如何做到這一點。 對於信息,我可以在應用程序中使用CodeIgniter來獲取更多信息(如果這樣做更容易的話)。
您可以使用我使用的這種方式。 在上一頁的頂部鍵入:
<?php
session_start();
$_SESSION['mainpass']= '0';
?>
在下一頁代碼中,該代碼位於頁面頂部:-
<?php
session_start;
if(isset($_SESSION['mainpass'])) {
//run the current page
}else{
header("location: www.domain.com");
}
?>
如果您使用codeigniter,則可以嘗試以下操作。
$seg3 = $this->uri->segment(3);
if(is_numeric($seg3)){
//The user has come without the header because the third segment is numeric thus probably using the product id.
//Therefore, redirect again to the proper link after getting the heading from your db
} else {
// do nothing
// the seg3 is not numeric means it probably came through normal preferred way
}
並且為了使用
$this->uri->segment(3);
你需要
自動加載網址幫助器
需要時手動加載
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.