Answer the question
In order to leave comments, you need to log in
How to configure mod_rewrite correctly?
The essence is clear: you need to bring all requests to the site of the form /path/to/file.html into the index.php file with the appropriate GET parameters. I saw several solutions on the net, but I'm not sure if I'm using the correct one (for example, I can't see the Yandex metric click map because of its get parameters)
Here's what I use:
RewriteRule ^([^/]*)\.html $ /index.php?query=$1 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?query=$1&id=$2 [L]
RewriteRule ^( [^/]*)/([^/]*)/([^/]*)\.html$ /index.php?query=$1&id=$2microid=$3 [L]
How to do better?
Answer the question
In order to leave comments, you need to log in
I would do it differently if I were you.
I would parse the URI string not in htaccess, but in index.php. And all requests to non-existent files would be passed unchanged to index.php. This is how they do it in all frameworks now. Then the _GET parameters will all remain, if necessary. An htaccess example (look at the last three conditions):
github.com/kohana/kohana/blob/3.0.x/example.htaccess
Then you can find it in a script like this:
github.com/kohana/core/blob/3.0.x/ classes/kohana/request.php#L239
and parse as needed for your query, id and microid.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question