本文介绍了使用 htaccess 对类别进行 url 重写 &php中的产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我完成我的项目,它是关于核心 php 中的电子商务网站,因为我是初学者

对于我的网站,我想要类别、子类别、产品和产品详细信息页面的 seo 友好网址....

我有这样的页面:

mysite.com/category.php?category_slug=mobiles : 分类页面mysite.com/subcategory.php?subcategory_slug=samsung :子类别页面mysite.com/product.php?product_slug=galaxy-note:产品页面我想像这样重写这些网址:mysite.com/mobiles:类别mysite.com/samsung:子类别mysite.com/galaxy-note:产品页面

我的 htaccess 代码是

重写引擎开启选项 - 多视图重写基数/RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^([a-zA-Z0-9-]+)$ category.php?category_slug=$1 [NC,L]重写规则 ^([a-zA-Z0-9-]+)$ subcategory.php?subcategory_slug=$1 [NC,L]重写规则 ^([a-zA-Z0-9-]+)$ products.php?product_slug=$1 [L]

任何帮助将不胜感激...

解决方案

在^前添加页面名称

RewriteRule ^category/([a-zA-Z0-9-]+)$ category.php?category_slug=$1 [NC,L]RewriteRule ^subcategory/([a-zA-Z0-9-]+)$ subcategory.php?subcategory_slug=$1 [NC,L]重写规则 ^products/([a-zA-Z0-9-]+)$ products.php?product_slug=$1 [L]

并写下您的类别页面网址,例如 category/mobiles/

更新

原始网址:mysite.com/category.php?category_slug=mobiles重写后的网址:mysite.com/mobiles

RewriteRule ^([^/]*)$/category.php?category_slug=$1 [L]

原始网址:mysite.com/subcategory.php?category_slug=mobiles&subcategory_slug=samsung重写后的网址:mysite.com/mobiles/samsung

RewriteRule ^([^/]*)/([^/]*)$/subcategory.php?category_slug=$1&subcategory_slug=$2 [L]

原始网址:mysite.com/products.php?category_slug=mobiles&subcategory_slug=samsung&product_slug=galaxy-note重写后的网址:mysite.com/mobiles/samsung/galaxy-note

RewriteRule ^([^/]*)/([^/]*)/([^/]*)$/products.php?category_slug=$1&subcategory_slug=$2&product_slug=$3[L]

please help me to complete my project its about ecommerce site in core php as i am a beginner

for my site i want seo friendly url for category, subcategory, product and product detail page....

i have pages like this :

mysite.com/category.php?category_slug=mobiles         : category page
mysite.com/subcategory.php?subcategory_slug=samsung   :   subcategory page
mysite.com/product.php?product_slug=galaxy-note       :   product page

and i want to rewrite these url like this :

mysite.com/mobiles        :   category
mysite.com/samsung        :   sub category
mysite.com/galaxy-note    :   product page

my htaccess code is


RewriteEngine On
Options -Multiviews
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9-]+)$ category.php?category_slug=$1 [NC,L]

RewriteRule ^([a-zA-Z0-9-]+)$ subcategory.php?subcategory_slug=$1 [NC,L]

RewriteRule ^([a-zA-Z0-9-]+)$ products.php?product_slug=$1 [L]


any help would be appreciated...

解决方案

add page name before ^

RewriteRule ^category/([a-zA-Z0-9-]+)$ category.php?category_slug=$1 [NC,L]

RewriteRule ^subcategory/([a-zA-Z0-9-]+)$ subcategory.php?subcategory_slug=$1 [NC,L]

RewriteRule ^products/([a-zA-Z0-9-]+)$ products.php?product_slug=$1 [L]

and write your url for category page as example category/mobiles/

UPDATE

The original URL:mysite.com/category.php?category_slug=mobilesThe rewritten URL:mysite.com/mobiles

RewriteRule ^([^/]*)$ /category.php?category_slug=$1 [L]

The original URL:mysite.com/subcategory.php?category_slug=mobiles&subcategory_slug=samsungThe rewritten URL:mysite.com/mobiles/samsung

RewriteRule ^([^/]*)/([^/]*)$ /subcategory.php?category_slug=$1&subcategory_slug=$2 [L]

The original URL:mysite.com/products.php?category_slug=mobiles&subcategory_slug=samsung&product_slug=galaxy-noteThe rewritten URL:mysite.com/mobiles/samsung/galaxy-note

RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /products.php?category_slug=$1&subcategory_slug=$2&product_slug=$3 [L]

这篇关于使用 htaccess 对类别进行 url 重写 &php中的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:34