简体   繁体   中英

htaccess RewriteCond OR flag not working as expected

I have a wordpress website and I am trying to filter out certain useragents based on parts of their string names

I'm using this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %[HTTP_USER_AGENT] .*useragent3.* [NC, OR]
RewriteCond %[HTTP_USER_AGENT] .*useragent2.* [NC, OR]
RewriteCond %[HTTP_USER_AGENT] .*useragent1.* [NC]
RewriteRule ^.* - [F,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Doing so, I get a 500 error and I've noticed that if I remove the OR flag I get rid of the 500 error and the website shows up but it does not filter the useragents. This is normal behavior since the OR flag adds the OR statement to my RewriteCond query as the default would be AND and would require that the useragent name to match all of those strings.

The question remains, why I get a 500 error when using OR?

Remove the whitespace in your flags

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %[HTTP_USER_AGENT] .*useragent3.* [NC,OR]
RewriteCond %[HTTP_USER_AGENT] .*useragent2.* [NC,OR]
RewriteCond %[HTTP_USER_AGENT] .*useragent1.* [NC]
RewriteRule ^.* - [F,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Should work

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