.htaccessmod-rewriteurl-rewriting

Using multiple rewrite rules


I'm trying to create multiple rewrite rules to make friendly URLs, but it makes my website throw error 500.

I've tried this, but I can't seem to make it work.

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*) /index.php?category=$1 [L]
RewriteRule ^(.*)/(.*) /index.php?category=$1&subcategory=$2 [L]
RewriteRule ^(.*)/(.*)/(.*) /index.php?category=$1&subcategory=$2&userid=$3 [L]

I basically need to make these URLs work:

domain.com/GetAnnouncements as domain.com/index.php?category=GetAnnouncements
domain.com/Persona/GetAchievements/2 as domain.com/index.php?category=Persona&subcategory=GetAchievements&userid=2

And there also should be a third option that works 'in between' without the third parameter which is &userid=2.


Solution

  • We came to this solution, which works:

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^(.*)/(.*)/(.*)$ index.php?category=$1&subcategory=$2&userid=$3 [L,QSA]
    RewriteRule ^(.*)/(.*)$ index.php?category=$1&subcategory=$2 [L,QSA]
    RewriteRule ^(.*)$ index.php?category=$1 [L,QSA]