htaccess rewrite rule - if the parameter value has forward slashes

20 Views Asked by At

We're building an API and I'm working on the rewriterule of my htaccess to make our URL like this example.com/student/user/parameter1/parameter2.

Everything is working fine until I caught a problem:

The parameter2 consists of random alphanumeric and special characters, and it also includes a forward slashes (/). So whenever we're running the endpoint and captures the parameters, the values are wrong because it's reading the slashes within the parameter

Example: example.com/student/user/anna/a!p=/dfa

  • Expected result should be parameter1 is anna and parameter2 is a!p=/dfa
  • What's happening is parameter1 is a!p= and parameter2 is dfa

I'm hoping somebody would give me an idea on how to fix this.

This is our current .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^student/user/(.*)/(.*)$ api/studentuser.php?name=$1&token=$2 [L]
0

There are 0 best solutions below