关于系统
我的项目中有这种格式的URL: -
http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
Run Code Online (Sandbox Code Playgroud)
其中关键字/类对意味着使用"class"关键字进行搜索.
我有一个常见的index.php文件,它为项目中的每个模块执行.只有一个重写规则可以从URL中删除index.php: -
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)
我在阅读搜索URL时准备搜索URL和urldecode()时使用urlencode().
问题
只有正斜杠字符会破坏导致404页面未找到错误的URL.例如,如果我搜索one/twoURL是
http://project_name/browse_by_exam/type/tutor_search/keyword/one%2Ftwo/new_search/1/search_exam/0/search_subject/0/page_sort/
Run Code Online (Sandbox Code Playgroud)
我该如何解决?我需要将index.php隐藏在URL中.否则,如果不需要,那么正斜杠就没有问题了,我可以使用这个URL: -
http://project_name/index.php?browse_by_exam/type/tutor_search/keyword/one
%2Ftwo/new_search/1/search_exam/0/search_subject/0
Run Code Online (Sandbox Code Playgroud) 我正在做客户的以下请求:
/search/hello%2Fthere/
其中搜索词"hello/there"已经过网址编码.
在服务器上,我尝试使用以下请求映射匹配此URL:
@RequestMapping("/search/{searchTerm}/")
public Map searchWithSearchTerm(@PathVariable String searchTerm) {
// more code here
}
Run Code Online (Sandbox Code Playgroud)
但我在服务器上收到错误404,因为我没有任何匹配的URL.我注意到在Spring获取之前解码了URL.因此,尝试匹配/ search/hello /那里没有任何匹配.
我在这里找到了一个与此问题相关的Jira:http://jira.springframework.org/browse/SPR-6780.但我仍然不知道如何解决我的问题.
有任何想法吗?
谢谢