[英].htacces redirect when $1 is empty
I'm building an online shop and I'm trying to redirect every shop subfolder to the standard shop.php page displaying the results filtered by the url path as a category. 我正在建立一个在线商店,并且试图将每个商店子文件夹重定向到标准shop.php页面,该页面显示按url路径作为类别过滤的结果。
the structure is mydomain.com/shop/category where category is a field stored on the database. 结构为mydomain.com/shop/category ,其中category是存储在数据库中的字段。
I use the following php code for filtering the results: 我使用以下php代码过滤结果:
$url = isset($_GET["url"]) ? $_GET["url"] : false;
if (!$url)
$where_products = "WHERE 1";
else
$where_products = "WHERE c.url = '$url'";
/* list products filtered by where clause */
$sql_products = "SELECT p.name FROM `product` p INNER JOIN `category` c ON p.id_category = c.id $where_products LIMIT 0,80";
now I have the following .htaccess file for redirecting the subfolder to the correct url variable: 现在,我有以下.htaccess文件,用于将子文件夹重定向到正确的url变量:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^shop/([^/\.]+)/?$ shop.php?url=$1 [L]
now everything works fine, but when I try to show all products using mydomain.com/shop/ I get the follwing error message 现在一切正常,但是当我尝试使用mydomain.com/shop/显示所有产品时,出现以下错误消息
/shop/ was not found on this server 在此服务器上找不到/ shop /
what can I do on the .htaccess file to redirect correctly all products when no subfolder is called? 在不调用子文件夹的情况下,如何对.htaccess文件正确地重定向所有产品?
Tweak your regex to support 0 or more characters instead of 1 or more characters
. 调整您的正则表达式以支持0个或多个字符,而不是1 or more characters
。
Try this rule: 尝试以下规则:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^shop/([^/.]*)/?$ /shop.php?url=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.