1

I want to following url :

nl/provincies/Limburg/plaats/#CITY# for example : nl/provincies/Limburg/plaats/Amsterdam

To be rewriten to section.php?sid=plaatsen$plaats=#CITY#

Ofcourse this is not so difficult by using :

^nl/provincies/plaatsen/(.*)$ section.php?sid=plaatsend&plaats=$1

But the problem comes when I also want to do this for :

nl/provincies/#STATE#

for example : nl/provincies/Limburg

To be rewriten to section.php?sid=plaatsen$province=#STATE#

Now the problem comes and this does not work. It sees provincies/Limburg/plaats/Echt

As one province, the province : Limburg/plaats/Echt

I tried to be creative and used :

RewriteCond %{REQUEST_URI} !^nl/provincies/plaats/(.*)$
RewriteRule ^provincies/(.*)$ section.php?sid=plaatsen&province=$1

RewriteCond %{REQUEST_URI} ^nl/provincies/plaats/(.*)$
RewriteRule ^nl/provincies/plaatsen/(.*)$   section.php?sid=plaatsend&plaats=$1

Any ideas / solutions ? Thanks guys !

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
r-d-r-b-3
  • 325
  • 2
  • 11

1 Answers1

0
^nl/provincies/plaatsen/(.*)$ section.php?sid=plaatsend&plaats=$1

...this will never match the URL you've given?

Anyway what you're looking for is something like:

RewriteRule ^(.+)/provincies/([^/]+)$         section.php?sid=plaatsend&plaats=$2
RewriteRule ^(.+)/provincies/.+/plaats/(.+)$  section.php?sid=plaatsend&province=$2

Or more generic:

RewriteRule ^(.+)/provincies/([^/]+)(/plaats/)?(.+)?$ section.php?sid=plaatsend&province=$2&plaats=$4&locale=$1

For complex rewriting like this I would however sincerely recommend doing it in PHP.

Community
  • 1
  • 1
Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • Niels, really apriciated your post. Many thanks ! Yes, I did see that it does not match. But you already gave me the right answer. ([^/]+) is that a wildcard for every directory except plaats ? Also you mixed up the section.php, they should be otherwise. – r-d-r-b-3 Jul 17 '13 at 11:36
  • Really works excellent Niels ! This solutions popped up 2 questions : What is $1 and $2 in your example. Because I only see $1 as the province or place ([^/] stands for a directory which comes after provincies ? This can be everydirectory except place ? Right ? – r-d-r-b-3 Jul 17 '13 at 11:43
  • a) Read up on regexps ;) `[^/]` matches any character except the slash. b) $1 and $2 refer to the first and second match (the parenthesized blocks in the regexp, like `(.+)`. I think those 2 additions should answer all questions :) My 'more generic' solution just makes a lot of things optional with the `?` suffix, ensuring all URLs can be passed through the same regexp. – Niels Keurentjes Jul 17 '13 at 12:27