Url使用动态类别重写

Hi guys I need help from all you brilliant people . I am creating a shopping website I am stuck while rewriting a url for product categories what I want to do is rewrite the url for categories for eg.

www.mysite.com/mens/

www.mysite.com/womens

These are main categories in my database What I am doing right now is www.mysite.com/mens.php www.mysite.com/womens.php For rewriting my url I have to create a php page physically in directory to work So what now I want the url as same as

www.mysite.com/mens

www.mysite.com/womens

But I don't want to create the " mens.php,womens.php " page physically in the directory instead I want to make a master page that load all data for the all categories and show it as url whatever category is clicked as

www.mysite.com/mens

www.mysite.com/womens

And Same for the subcategories scenario

Create .htaccess file in root directory and copy paste following text in it and try

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^ %{REQUEST_URI}.php [NC,L]

I would trap the 2 main categories and route all subcategories to same page show-categ.php. You could actually route all requests via one single script, but I do not know anything about the rest of the website. show-categ.php could check subcat in a database ... , I suspect you are showing data driven content.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/?mens/(.+?)/$ /app/show-categ.php?cat=mens&subcat=$1 [QSA,L]
RewriteRule ^/?womens/(.+?)/$ /app/show-categ.php?cat=womens&subcat=$1 [QSA,L]