Reputation: 1129
I have this rule which works perfectly
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+) /demo/index.php?category=$1&subcategory=$2
this converts my link from
/demo/index.php?category=ABC&subcategory=XYZ
to
/demo/ABC/XYZ
but at times I want to enter just the category name like this
/demo/ABC/
But unfortunately this gives error Page not found. What causes this error and how can I fix it?
Also can someone provide link to RewriteEngine resources/books/tutorials. I couldn't find anything that would help a beginner like me. Thank you.
Upvotes: 1
Views: 81
Reputation: 784878
Change your rule to:
RewriteRule ^([^/]+)/([^/]*) /demo/index.php?category=$1&subcategory=$2 [L,QSA]
This making second argument optional (using *
instead of +
in [^/]*
)
Upvotes: 1
Reputation: 233
Unless /demo/ABC/
is a directory that exists on your local file system, it won't be able to find the page. Your first rule is only rewriting that parameter-filled link into that pseduo-path, it doesn't establish a virtual directory or create a solid redirect.
The best info for RewriteRule
is probably going to be in the actual Apache docs.
Upvotes: 0