简体   繁体   中英

htaccess no working fine with some character

This is my url rule:

RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/?$ controller/$1/$1.php?id=$2 [L]

working fine with : http://yii.abc.com/category/Grand-Opening but no working with : http://yii.abc.com/category/I'm-sorry and

http://yii.abc.com/category/Wedding-&-ROM

Try this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w=-]+)/([^/]+)/?$ controller/$1/$1.php?id=$2 [L,QSA,B]

Using B flag is the key here to be able to pass whole Wedding-&-ROM as GET parameter.

That's because you haven't included characters ' and & in your character class.

You can fix it by including them like this.

Regex: ^([a-zA-Z0-9_=-]+)\\/(['&a-zA-Z0-9_=-]+)\\/?$

Regex101 Demo

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