提问人:Amir 提问时间:2/11/2021 最后编辑:RavinderSingh13Amir 更新时间:2/11/2021 访问量:85
重写规则数组 从 url 中隐藏类别
Rewrite rules array hide the category from url
问:
我使用下面的重写规则数组来重写 URL。
$rules = array(
'image' => "/image/(?'image'[\w\-]+)", // '/image/image-slug'
'product-category' => "/product-category/(?'product_category'[\w\-]+)", // '/product-category/category-slug'
'product' => "/product/(?'product'[\w\-]+)", // '/product/product-slug'
'post' => "/(?'post'[\w\-]+)", // '/post-slug'
'home' => "/" // '/'
);
这是我的.htaccess。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} baqsa\.pk [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.baqsa.pk/$1 [R,L]
</IfModule>
当前 URL 是 like 等。我想从 URL 中删除或隐藏。我想要像这个 URL 当我从这里的数组中删除时,它工作正常,但帖子不起作用。.我在这里错过了什么?domain.com/product-category/category-slug
product-category
domain.com/category-slug
product-category
'product-category' => "/(?'product_category'[\w\-]+)",
'post' => "/(?'post'[\w\-]+)",
答:
0赞
RavinderSingh13
2/11/2021
#1
根据您展示的样品,您可以尝试以下内容。将your_site更改为您的实际域名,此外,请确保在测试您的 URL 之前清除浏览器缓存。
RewriteEngine ON
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://www.your_site%{REQUEST_URI} [R=301,NE,L]
RewriteRule ^product-category/(.*)/?$ $1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
评论
domain.com/products
domain.com/product-category/products
domain.com/product-category/category-slug
domain.com/category-slug
product-category
domain.com/product-category/category-slug
domain.com/category-slug