在直接页面上,我的购物车正常工作,例如链接:http://sriads.com/shopping/latest/
(index.php
)。
但它没有使用这些链接,它来自.htaccess
:
http://www.sriads.com/shopping/product/13/tp-link-4-port-wireless-dual-band-n600
弹出框也可以,但不是购物车。这是怎么回事?我已经看到了这个问题,它适用于域名的非www形式,但不适用于www地址。
此链接无效:
http://www.sriads.com/shopping/product/13/tp-link-4-port-wireless-dual-band-n600
这是我的代码ajax.php
(它是一个jQuery弹出框):
session_start();
require '_include/core.inc.php';
require_once("_include/dbcontroller.php");
$db_handle = new DBController();
function checkCartForItem($addItem, $cartItems) {
if (is_array($cartItems)){
foreach($cartItems as $key => $item) {
if($item['id'] === $addItem)
return $key;
}
}
return false;
}
$cart_id = $_POST['id'];
$qtyget = $_POST['quantityValue'];
if (!empty($_POST['quantityValue'])) {
$qty = $_POST['quantityValue'];
} else {
$qty = 1;
}
//Store it in a Array
$ITEM = array(
//Item name
'id' => $_POST['id']
);
$addItem = $_POST['id'];
if (!empty($_POST['id'])) {
if (!empty($qty)) {
$productByCode = $db_handle->runQuery("SELECT * FROM product WHERE id='" . $_POST["id"] . "'");
$itemArray = array($productByCode[0]["id"]=>array('name'=>$productByCode[0]["product_name"], 'id'=>$productByCode[0]["id"], 'quantity'=>$qty, 'price'=>$productByCode[0]["new_price"]));
$itemExists = checkCartForItem($addItem, $_SESSION['cart_item']);
if ($itemExists !== false){
// item exists - increment quantity value by 1
$_SESSION['cart_item'][$itemExists]['quantity']++;
} else {
if(!empty($_SESSION["cart_item"])) {
if(in_array($productByCode[0]["id"],$_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($productByCode[0]["id"] == $k)
$_SESSION["cart_item"][$k]["quantity"] = $qty;
}
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
}
}
}
.htaccess(http://sriads.com/shopping/product/
)
<Files .htaccess>
order allow,deny
</Files>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /shopping/product/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^(\w+)/(.*)$ ./load.php?id=$1
RewriteRule ^(\w+)/*$ ./load.php?id=$1
内部页面重定向到www但/ajax.php中的会话页面未重定向到www
我用.htaccess回家
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]