关于系统
我的项目中有这种格式的 URL:-
http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
其中keyword/class
pair表示使用“class”关键字进行搜索。
以下是我的 htaccess 文件:-
##AddHandler application/x-httpd-php5 .php
Options Includes +ExecCGI
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
############To remove index.php from URL
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
#################################################end of find a class
</IfModule>
我有一个通用的 index.php 文件,它为项目中的每个模块执行。只有一个重写规则可以从 URL 中删除 index.php(如上所示)。
我没有使用任何 htaccess 重写规则来定义 $_GET 数组。我在 PHP 中有一个 URL 解析器函数来代替它。对于我给出的示例 URL,解析器返回:-
Array ( [a] => browse_by_exam [type] => tutor_search [keyword] => class [new_search] => 1 [search_exam] => 0 [search_subject] => 0 )
我在准备搜索 URL 时使用 urlencode(),在阅读搜索 URL 时使用 urldecode()
问题
我遇到了 URL 中某些字符的问题
Character Response
% 400 - Bad Request - Your browser sent a request that this server could not understand.
/ 404 - Not FOund
\ # + Page does not break but urldecode() removes these characters.
我想允许所有这些字符。可能是什么问题呢?我如何允许这些?请帮助谢谢, Sandeepan
更新
现在只有 / 字符会导致 URL 中断(像以前一样的 404 错误)。因此,我尝试删除隐藏在 URL 中的 index.php 的 htaccess 重写规则,并尝试使用完整的 URL。class/new
对于我尝试使用以下两个 URL的搜索词:-
http://project_name/index.php?browse_by_exam/type/tutor_search/keyword/class%2Fnew/new_search/1/search_exam/0/search_subject/0
http://project_name/index.php/browse_by_exam/type/tutor_search/keyword/class%2Fnew/new_search/1/search_exam/0/search_subject/0
第一个有效,但第二个无效。注意index.php?browse_by_exam
第一个。
但我不能使用第一个 URL 约定。我必须隐藏 / 使用 index.php。请帮忙
再次感谢桑迪潘
编辑(已解决)
考虑到 Bobince 对我的另一个问题的回答
urlencoded 正斜杠破坏了 URL
,我觉得最好有这样的 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.