.htaccess mod_rewrite正在弄乱我的URL中的方括号[]

时间:2015-08-15 08:46:52

标签: .htaccess mod-rewrite

我几天前在.htaccess文件中更改了一些内容,现在注意到URL中的括号现在搞砸了。而不是:

url.com/admin/page?delete[]=12345&reasons[]=2

网址显示为:

url.com/admin/page?delete%255B%255D=12345&reasons%255B%255D=2

可能导致这种情况的原因是什么?这是我的.htaccess文件。它让我发疯了!

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]

RewriteRule ^admin/page/?$ admin/page.php [L,NC]

RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^.* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com/profile?user=%1 [L,QSA]


RewriteRule ^([^/]*)-([0-9]+)\.html$ product?name=$1&id=$2 [L,QSA]

ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php

1 个答案:

答案 0 :(得分:1)

你的规则如下:

ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302,NE]

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]

RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=302,NE]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com/profile?user=%1 [L,QSA,R=302,NE]

RewriteRule ^([^/]+)-([0-9]+)\.html$ product?name=$1&id=$2 [L,QSA]

RewriteRule ^admin/page/?$ admin/page.php [L,NC]
  • 在重写之前保留重定向规则,并在每个重定向规则中使用NE标志。
  • 确保在测试前清除浏览器缓存。