Jump to content

[SOLVED] Modifying .htaccess file to display sub category


ali_kiyani

Recommended Posts

Hi,

 

I have the following .htaccess file:

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+) displaypage.php?page=$1 [NC,L]

 

Using it I can read URLs like this:

 

www.mywebsite.com/cats

www.mywebsite.com/cars

www.mywebsite.com/computers

 

Now I want to modify .htaccess file so it can also read the following:

 

www.mywebsite.com/cars/bmw

www.mywebsite.com/computers/pc

 

Think of 'cars' as category and 'bmw' as subcategory. I want to read both but because of my current .htaccess file I can only read categories and nothing after it.

 

Thanks

Link to comment
Share on other sites

You'll have to setup a second rule for this, eg:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# matchs mysite.com/cars/bmw
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+) displaypage.php?page=$1&sub=$2 [NC,L]

# matches mysite.com/cars
RewriteRule ^([a-z0-9-]+) displaypage.php?page=$1 [NC,L]

 

To retrieve the sub catergory in displaypage.php you'll use $_GET['sub']

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.