Divakarcool
Divakarcool

Reputation: 481

.htaccess Pretty URL rewrite like folder

I am trying to rewrite one of my urls to pretty urls but I can't seem to figure it out. Here is what I've tried far.

My folder layout

-index.php
-.htaccess
-/product
    -category.php
    -index.php
    -product.php

my htaccess file

<IfModule mod_rewrite.c>  
RewriteEngine On
RewriteRule ^([^/]+)/?$ category.php?category_id=$1 [L,QSA]
</IfModule>

i'm tring to turn this url

http://example.com/product/category.php?category_id=1&category=car-and-buses

into this url

http://example.com/product/1/car-and-buses

everything what i tried so far gives me miss-configuration error or 401.. on my browser

Upvotes: 2

Views: 668

Answers (1)

Andy
Andy

Reputation: 397

I guess you try to turn

http://example.com/product/1/car-and-buses

into this so you can fetch the parameters in your category.php with $_GET['category_id']

http://example.com/product/category.php?category_id=1&category=car-and-buses

Try this and place the .htaccess file in your root

<IfModule mod_rewrite.c>
  RewriteEngine On      
  RewriteRule ^product/(.*)/(.*) /product/category.php?category_id=$1&category=$2 [QSA,L]
</IfModule>

EDIT!

Try this since the above solution doesn't work for you. This should rewrite all request to your index.php. This is not a solution to your question but try this to make sure there isn't any other problem whit your .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?page=$1 [NC,L,QSA]

Upvotes: 1

Related Questions