Apache Mod rewrite question


I currently use the following rewrite rule:

rewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)$ script.php?user=$1

this works well to redirect domain.com/blabla to domain.com/script.php?user=blabla
But it doesn’t work when blabla contains spaces:

domain.com/bla bla results in a 404.

I would like to redirect the above to domain.com/script.php?user=bla bla

I suppose I should change the ^([a-zA-Z0-9_-]+) part to include spaces
Who can help please?


In the URL string, spaces are changed to plus signs. You probably get the user name from an input field. When you submit a form from an HTML page, the conversion is done automatically. But, if you send it using “Ajax”, you need to translate it using “encodeURIComponent”. So, I would add ‘+’ and ‘%’ in the brackets.