简体   繁体   中英

RewriteRule: bad flag delimiters

Here is my .htaccess file:

ErrorDocument 404 /index.php?cmd=notfound
# Maintenance
RewriteCond %{REMOTE_ADDR} !^(Redacted)
RewriteRule ^ maintenance.php [L]

RewriteEngine On 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)(?:/(\w+))?(?:/(\w+))?(?:/(\w+))?(?:/(\w+))?(?:/(\w+))?/?$ route.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6 [L]

It works, no errors, however there is a problem: the last RewriteRule doesn't allow spaces in the arguments.

I was told by somebody to replace \\w+ with [\\w ]+ , but when I do that I get an error:

RewriteRule: bad flag delimiters

Zapk, it sounds like HamZa already told you the solution: yes, \\s will match spaces (as in most regex flavors).

For completion, here is a fact that is too-little known: Apache uses PCRE for regex matching. This is great news for web admins as PCRE is one of the most full-featured engines around. So you can do a lot of things beyond the usual ugly examples of Apache redirects floating around the interweb.

As a start, I must say that it's a pleasure to the eyes to see that you are using an unescaped forward slash in your regex, while many examples around the web make a big soup of unnecessary \\/\\/ It's also a treat to see that you are using non-capturing groups.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM