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

问题描述

请帮我完成我的项目,因为我是初学者,所以在核心php中完成了有关电子商务网站的

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

对于我的网站,我希望使用seo友好的URL,用于类别,子类别,产品和产品详细信息页面。...

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

我有这样的页面:

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

我的htaccess代码是

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...

推荐答案

在^之前添加页面名称p>

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]

并输入类别页面的网址,例如category / mobiles /

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

UPDATE

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

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

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

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

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]

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

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对类别&进行网址重写PHP产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 19:34