Search code examples
apache.htaccessmod-rewrite

.htaccess Redirect Rule for & Character


Im not experienced with .htaccess files. I apologize for misconceptions in advance.

If have the following rule in my .htaccess file to accept requests without a filename extension:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^index/([0-9a-zA-Z_-]+)/([öäü0-9a-zA-Z_-]+) index.php?id=$1&term=$2 [NC,L]

An URL like domain.com/index/2/jonathan should be (internally) redirected to domain.com/index.php?id=2&term=jonathan. This works fine except for terms which include the & character.

Adding the & character to the rule like this didnt help:

RewriteRule ^index/([0-9a-zA-Z_-]+)/([öäü0-9a-zA-Z_-&]+) index.php?id=$1&term=$2 [NC,L]

How can I include the & character correctly inside the rule? I appreciate any help.


Solution

  • Thanks, I was able to solve the problem using the B flag:

    RewriteRule ^index/([0-9a-zA-Z_-]+)/([öäü&0-9a-zA-Z_-]+) index.php?id=$1&term=$2 [B,NC,L]