2

I'm using this rewrite rule to redirect my search requests:
RewriteRule ^search/([^/\.]*)/([^/]+)/?$ index.php?search=$1&additional=$2 [L]

This rule works fine for
search/search/add
but it gives me a page not found for
search//add (empty search)

What am I doing wrong? The regex should match:

Regular expression visualization

Debuggex Demo

Jofkos
  • 739
  • 1
  • 9
  • 27

1 Answers1

4

Yes your regex will match search//add but problem is that mod_rewrite engine strips multiple slashes into single one in RewriteRule directive.

You can use a RewriteCond instead:

RewriteCond %{REQUEST_URI} ^/search/([^/.]*)/([^/]+)/?$ [NC]
RewriteRule ^ index.php?search=%1&additional=%2 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643