Search code examples
regexapache.htaccessmod-rewritesearch-engine

URL-Rewriting /Anything/Variable detail.php?pid=variable


o/

I am trying to rewrite my URL's.

If i'd go to: http://mydomain.com/vakanties/Verenigde%20Staten/Orlando/E6220

it should get parsed to: http://mydomain.com/detail.php?pid=E6220

However, X should be able to be any random word, including spaces and special characters

http://mydomain.com/vakanties/ X / X / Y

Everything I've tried has resulted me with a 404 so far. The module is activated and the engine is on. These are the rules that I have tried:

RewriteRule ^vakanties/[\w +]/[\w +]/([\w]*) detail.php?pid=$1
RewriteRule ^vakanties/[A-Za-z0-9-]+/[A-Za-z0-9-]+/([A-Za-z0-9-]+) detail.php?pid=$1
RewriteRule ^vakanties/[a-zA-Z0-9%+]/[a-zA-Z0-9%+]/([a-zA-Z0-9%+]*)$ detail.php?pid=$1
RewriteRule ^vakanties/[\w\ +]/[\w\ +]/([\w]*) detail.php?pid=$1
RewriteRule ^vakanties/[\w\ +]/[\w\ +]/([\w]*)$ detail.php?pid=$1

Any help, links, suggestions or tips would be greatly appriciated.

Thanks in advance!


Solution

  • Instead of [\w +] use negation regex like [^/]+ like this:

    RewriteRule ^vakanties/[^/]+/[^/]+/([^/]+)/?$ detail.php?pid=$1 [L,QSA]