Rewrite URL of custom php based E-Commerce Website

2019-09-10 02:05发布

I have experimented a lot already however they did not work for me, so i have to put this query for which i need very specific solutions.

No CMS is used. The website is an eCommerce site developed using php

My site url structure is

  • For Product Pages = https://www[dot]sitename.com/product.php?product=productid
  • For Category Pages = https://www[dot]sitename.com/category.php?category=category-name
  • For SubCat Pages = https://www[dot]sitename.com/category.php?subcategory=sub-category-name

I want

  • For Product Pages = https://www[dot]sitename.com/product/productid/
  • For Category Pages= https://www[dot]sitename.com/category/category-name
  • For SubCat Pages = https://www[dot]sitename.com/category/subcategory/sub-category-name

How can i do this using .htaccess?

3条回答
太酷不给撩
2楼-- · 2019-09-10 02:25

Thank you all for your suggestions. However none of the methods worked for me. Let me add few more things about the site and hosting which may help you analyze my problem and provide alternative solutions.

  1. The website is hosted on Godaddy Shared Hosting
  2. The website is not using any CMS
查看更多
Anthone
3楼-- · 2019-09-10 02:35

Add this to your .htaccess in your web root / directory

RewriteEngine on
RewriteBase /

# Products    
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^product/([^/]+)/?$ product.php?product=$1 [NC,QSA,L]

# Categories
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^category/([^/]+)/?$ category.php?category=$1 [NC,QSA,L]

# Sub-categories
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^category/subcategory/([^/]+)/?$ category.php?subcategory=$1 [NC,QSA,L]
查看更多
Fickle 薄情
4楼-- · 2019-09-10 02:35

The following htaccess rules work for me, and hopefully these will work for you.

RewriteEngine On    # Turn on the rewriting engine

RewriteRule    ^category/([A-Za-z0-9-]+)/?$    category.php?category=$1   [NC,L]    # Handle category

RewriteRule    ^category/subcategory/([A-Za-z0-9-]+)/?$    category.php?subcategory=$1   [NC,L]    # Handle sub category

RewriteRule    ^product/([A-Za-z0-9-]+)/?$    product.php?product=$1   [NC,L]    # Handle product
查看更多
登录 后发表回答