K
K
Kirill Krasin2019-02-09 16:42:24
Apache HTTP Server
Kirill Krasin, 2019-02-09 16:42:24

How to write a RewriteRule for single and multi-level link nesting?

Hello. Help me write the right RewriteRule to organize the link hierarchy.
I have the following URL structure:

example.com/index.php?game=mario&selector=news&value=22

And the corresponding rules in .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?game=$1&selector=$2&value=$3 [L,QSA]

The above rule works fine and the URL looks like this:
example.com/mario/news/22
However, if I try to go to example.com/mario/ , I get a 404 error , while example.com/mario/news/ shows the content, just like and example.com/index.php?game=mario

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-02-09
@Mo45

Add rule for /mario/
RewriteRule ^([^/]*)/$ /index.php?game=$1 [L,QSA]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question