0

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

2 Answers 2

0

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=mobiles The rewritten URL: mysite.com/mobiles

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

The original URL: mysite.com/subcategory.php?category_slug=mobiles&subcategory_slug=samsung The 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-note The rewritten URL: mysite.com/mobiles/samsung/galaxy-note

RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /products.php?category_slug=$1&subcategory_slug=$2&product_slug=$3 [L]
Sign up to request clarification or add additional context in comments.

21 Comments

i tried it and it's working but i dont want like this
i want : mysite.com/mobiles
tell me how its define what page should use??
mysite.com/mobiles : RewriteRule ^([a-zA-Z0-9-]+)$ category.php?category_slug=$1 [NC,L]
but if i am doing the same for subcategory page then it's not working
|
0

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

remove the $ sign after category/([a-zA-Z0-9-]+)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.