【发布时间】:2011-03-15 04:40:25
【问题描述】:
关于系统
我的项目中有这种格式的 URL:-
http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
关键字/类对表示使用“类”关键字进行搜索。
我有一个为项目中的每个模块执行的通用 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]
我在准备搜索 URL 时使用 urlencode(),在读取搜索 URL 时使用 urldecode()。
问题
只有正斜杠字符会破坏 URL,导致 404 页面未找到错误。
例如,如果我搜索 one/two,则 URL 是
http://project_name/browse_by_exam/type/tutor_search/keyword/one%2Ftwo/new_search/1/search_exam/0/search_subject/0/page_sort/
我该如何解决这个问题?我需要将 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
【问题讨论】:
-
我觉得最好有这样的 URL:-
http://project_name/browse_by_exam?type/tutor_search/keyword/class %2Fnew/new_search/1/search_exam/0/search_subject/0这样我就摆脱了由 ¶m1=value1¶m2=value2 约定引起的可读性困难,而且我还可以允许正斜杠(现在在查询字符串部分使用?)我会避免使用AllowEncodedSlashes,因为Bobince 说Also some tools or spiders might get confused by it. Although %2F to mean / in a path part is correct as per the standard, most of the web avoids it.url .htaccess url-routing -
如果使用这种方式可以使用 %2F ?param1=value1¶m2=value%2Fvalue 但如果使用 /param1=value1/param2=value%2Fvalue 则会抛出错误。
标签: .htaccess url-rewriting http-status-code-404 url-encoding