我在我的項目這種格式的URL: -
http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
凡keyword/class
對意味着搜索「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)
我使用urlencode()處理,同時準備搜索網址和urldecode(),而讀搜索URL
問題
我正在面對一些字符在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
我試着用以下兩個網址: -
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
,第一個作品,但第二個一個沒有。請注意0在第一個。
但我不能使用第一個URL約定。我必須使index.php隱藏。請幫助
再次感謝 Sandeepan
編輯(解決)
考慮Bobince的回答我的其他問題
urlencoded Forward slash is breaking URL ,我覺得這是最好能有這樣的網址: - http://project_name/browse_by_exam?type/tutor_search/keyword/class %2Fnew/new_search/1/search_exam/0/search_subject/0
這樣,我擺脫了diffi的可讀性culty造成¶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(404錯誤)。請檢查更新部分,看看你是否可以提供幫助。 – 2010-07-13 07:13:33
我對我的答案做了一些更新;它不能解決你所描述的問題,但我不明白爲什麼它必須按照你描述的方式來完成。不過,我不確定是否有辦法讓它像你想要的那樣工作,但我不確定是否有可能(除非你將你的重寫規則移動到'httpd.conf'或者其他什麼地方,看起來好像沒問題)。 – 2010-07-13 09:00:16
我想隱藏index.php,就像它一直在我們的項目中一樣。我想隱藏編碼完成的語言信息(在我的情況下,PHP)。檢查我編輯的問題 真的很感謝你的幫助態度 謝謝, Sandeepan – 2010-07-13 11:20:14