简体   繁体   中英

Rewrite URL using php code

I have experimented a lot already. I have tried every possible combination using .htaccess file 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. Hosting provider is godaddy.

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 php code?

Maybe something like this

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-s [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]

RewriteRule ^product/([0-9]+)$ product.php?product=$1 [L]
RewriteRule ^category/([a-zA-Z0-9_]+)$ category.php?category=$1 [L]
RewriteRule ^category/subcategory/([a-zA-Z0-9_]+)$ category.php?subcategory=$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM