1

I've been trying to rewrite URLs within a subfolder, but without success. Nothing simply happens - no URL is rewritten at all. Please help!

I want this: www.example.com/fruits/?fruitName=apples&mode=buy

...to become this: www.example.com/fruits/apples/buy/

These rewrites will only occur in the /fruits/ folder. How is this done?

Here's the code that I have tried:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/fruits/$ /fruits/?fruitName=$1&mode=$2

Thank you!

Marcus Edensky
  • 924
  • 3
  • 13
  • 33

1 Answers1

1

You can use this code in your /fruits/.htaccess file:

RewriteEngine On
RewriteBase /fruits/

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ ?fruitName=$1&mode=$2 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Bumped into a small problem though - I'd like the .htaccess rewrite to allow hyphens. What should I change? Should I ask a new StackOverflow question about this? – Marcus Edensky Jan 07 '15 at 16:07
  • 1
    That's a minor change so no need of a new question. See edited rule. – anubhava Jan 07 '15 at 16:21