1

I've searched all over the web but have not been able to find answers, so i hope you can help me.

I try to rewrite both the page and the category in my Htaccess as follows: example.com/page.php?cat=berlin&page=2 to example.com/berlin/2. Category can be different like Stockholm, Oslo, Copenhagen ...

Is there anybody inside that can show me how to do it? Or refer to a place where they show it correctly. I have try to use %1 but it did not work.

RewriteRule ^(.*)$ /book.php?url=$1 [L]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • 1
    "Did not work" is never a sufficient problem description. Albeit you did seemingly look somthing up at least, still wondering why there's no attempt to even adapt e.g. `book.php` to `page.php` – mario Nov 23 '17 at 00:40

1 Answers1

0

You would need to use back-references and multiple capture groups to accomplish this. So something like:

RewriteRule ^/page.php\?cat=([a-z]+)&page=([0-9]+)$ /$1/$2 [L]

This is making several assumptions, including that cat is always alpha characters and page is always numeric. Also see the apache documentation here, specifically the section on Regex Back-Reference Availability.

Also, %1 would match a capture group in a preceding RewriteCond not the current RewriteRule which uses the $1 notation.

AfroThundr
  • 1,175
  • 2
  • 17
  • 28