htaccess 在遇到空格时无法重定向

htaccess fails to redirect when encounter whitespace

我正在使用 htaccess 进行清理 url。只要参数不带 whitespace 就可以正常工作。在这种情况下,它将 space 转换为 %20 并且我收到 404 错误。

所以基本上 URL:http://localhost:8080/series/dynamics/admin/cleanURL/green%20apple

给我 404 错误。但是 URL: http://localhost:8080/series/dynamics/admin/cleanURL/greenapple 工作正常。

还有什么方法可以从 URL 中删除目录详细信息,我试过了

RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ / [L,NC,R]

但不起作用

htaccess

<IfModule mod_rewrite.c>
     Options +MultiViews 
     Rewriteengine on
     RewriteBase /series/dynamics/admin/cleanURL/
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ / [L,NC,R]
     Rewriterule ^([a-zA-Z0-9]+)/?$ index.php?product=
     RewriteRule ^(.*)(\s|%20)(.*)$ /- [R=301,L,NE]
     #rewrite group and subgroup e.g. http://.../value1/value2/ [L,NC,QSA]
     Rewriterule ^([a-zA-Z0-9]+(.*)+)/([^/]+(.*)+)/?$ index.php?product=&subgroup= [L,NC,QSA]
     </IfModule>

您需要在站点根目录 .htaccess 中添加此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) series/dynamics/admin/cleanURL/ [L]

然后在/series/dynamics/admin/cleanURL/.htaccess中加入这些规则:

Options +MultiViews 
Rewriteengine on
RewriteBase /series/dynamics/admin/cleanURL/

RewriteCond %{THE_REQUEST} /series/dynamics/admin/cleanURL/(\S*)\s [NC]
RewriteRule ^ /%1 [L,R=302,NE]

RewriteRule ^([^\s\x20]*)[\s\x20]+(.*)$ - [L,R=302,NE]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

Rewriterule ^(\w+)/?$ index.php?product= [L,QSA]

#rewrite group and subgroup e.g. http://.../value1/value2/ [L,NC,QSA]
Rewriterule ^([a-zA-Z0-9]+(.*))/([^/]+(.*))/?$ index.php?product=&subgroup= [L,NC,QSA]