Reputation: 5157
I have the following rewrite.
RewriteRule ^/news/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ /pagebase.php?pbid=3656&nid=$1&title=$2 [QSA,L,I]
http://www.domain.com/news/1/new-event/
So that the above url will be rewritten as:
http://www.domain.com/pagebase.php?pbid=3656&nid=1&title=new-event
This works perfectly. However I want people to be able to type in:
http://www.domain.com/news without any query strings and have it rewrite as this:
http://www.domain.com/pagebase.php?pbid=3656&nid=&title=
However the match fails so I get a 404 error. Is there anyway I can rewrite my rule to make the last 2 query string options optional. I was able to figure it out using multiple rewrite rules and placing them in the correct order, but I'd like to get it so I can get it working with one rule.
Upvotes: 0
Views: 374
Reputation: 25524
Use two rewrite rules:
RewriteRule ^/news/([a-z0-9\-]+)/([a-z0-9\-]+)/?$ /pagebase.php?pbid=3656&nid=$1&title=$2 [QSA,L,I]
RewriteRule ^/news$ /pagebase.php?pbid=3656&nid=&title= [QSA,L,I]
Upvotes: 2