请帮助我完成我的项目关于核心php中的电子商务网站,因为我是初学者
对于我的网站,我想要类别,子类别,产品和产品详细信息页面的seo友好网址....
我有这样的页面:
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代码是
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]
任何帮助将不胜感激......
答案 0 :(得分:0)
在^
之前添加页面名称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]
并将您的类别页面的网址列为示例类别/ 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]