R
R
Rom Black2014-12-09 12:17:52
Apache HTTP Server
Rom Black, 2014-12-09 12:17:52

Mod_rewrite how to add handling of optional GET parameter to URL?

Given:
1. site.ru/?route=index
2. site.ru/?route=page
3. site.ru/?route=blog
4. site.ru/?route=blogpost&showpost=1
Need:
1. site. ru/index.html
2. site.ru/page.html
3. site.ru/blog.html
4. site.ru/blog/1.html
The problem is in the rule for the last example.
For the first three Rewrite Rules

RewriteEngine On
RewriteRule ^([^/]*)\.html$ /?route=$1 [L]

How to make route=blogpost&showpost=1 become blog/1.html ?
the showpost parameter is required only for route=blogpost and is not used anywhere else.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kovpashko, 2014-12-11
@MrBlack

RewriteRule ^blog\/+(.+)\.html /?route=blogpost&showpost=$1 [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question