Jump to content

RewriteCond for starting with case


Rommeo

Recommended Posts

Hello,

For a project integration I need to give access only to "Test-Robot/2022v11"

I was using this code when the test robot's name was just "robot" and it was working fine;

RewriteCond %{HTTP_USER_AGENT} !=robot
RewriteRule .* - [F,L]

This also did not work when the name changed into "Test-Robot"  (I guess it's because of the hypen that needs to be escaped?)

RewriteCond %{HTTP_USER_AGENT} !=Test-Robot
RewriteRule .* - [F,L]

Now robot's name is "Test-Robot/2022v11" and I need to write a rule for "starting with Test-Robot" (since the rest "/2022v11" will change), how can I write it?

I tried this and no success;

RewriteCond %{HTTP_USER_AGENT} !^Test\-Robot/*
RewriteRule .* - [F,L]

Thank you in advance.

Link to comment
Share on other sites

Are you sure the user agent really starts with Test-Robot? Nothing else in there?

The hyphen doesn't need to be escaped (it's not a special character) and /* means "zero or more /". You can put it in quotes just in case.

RewriteCond %{HTTP_USER_AGENT} "!^Test-Robot/"

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.