简体   繁体   中英

.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.

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]

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