ali_kiyani Posted March 20, 2009 Share Posted March 20, 2009 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 20, 2009 Share Posted March 20, 2009 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'] Quote Link to comment Share on other sites More sharing options...
ali_kiyani Posted March 21, 2009 Author Share Posted March 21, 2009 I tried it but didn't work. It still only prints $_GET["page"] value and when I use print $_GET["sub"] then nothing is printed on screen. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 21, 2009 Share Posted March 21, 2009 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] Quote Link to comment Share on other sites More sharing options...
ali_kiyani Posted March 21, 2009 Author Share Posted March 21, 2009 Thanks man....it works! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.