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

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']

Change your rewrite rules to

# 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]

Archived

This topic is now archived and is closed to further replies.

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