.htaccess%重写规则崩溃服务器



我需要使用urlencode()函数,该功能将使URL包含'%'符号。

我当前的重写不允许这些字符,因此我需要对其进行更新,而我尝试的尝试使整个服务器崩溃了。

示例URL/A标签:<a href="/edit-portfolio/MQ%3D%3D">Test Link</a>

旧的.htaccess(工作很棒,直到我需要urlencode()(

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)$ index.php?page=$1&c=$2 [NC,L]

.htaccess(崩溃站点(

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z_-%]+)/([0-9a-zA-Z_-%]+)$ index.php?page=$1&c=$ [NC,L]

您应该在字符类中照顾-,因为它可能会定义一个范围。只是为了确保一直逃脱:

RewriteRule ^([0-9a-zA-Z_-%]+)/([0-9a-zA-Z_-%]+)$ index.php?page=$1&c=$ [NC,L]
                         ^                  ^

[_-%]这个范围根本没有有效

或将其移至字符类的结尾:

RewriteRule ^([0-9a-zA-Z_%-]+)/([0-9a-zA-Z_%-]+)$ index.php?page=$1&c=$ [NC,L]

顺便说一句,一切都可以缩短为:

RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&c=$2 [NC,L]
                                                   ^ You missed this one

最新更新