About the system
I have URLs of this format in my project:-
http://project_name/browse_by_exam/type/tutor_search/keyword/class/new_search/1/search_exam/0/search_subject/0
Where keyword/class
pair means search with "class" keyword.
Following is my htaccess file:-
##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>
I have a common index.php file which executes for every module in the project. There is only a rewrite rule to remove the index.php from URL (as you can see above).
I am not using any htaccess rewrite rules for defining the $_GET array. I have a URL parser function in PHP inside which does that instead. For the example URL I gave, the parser returns:-
Array ( [a] => browse_by_exam [type] => tutor_search [keyword] => class [new_search] => 1 [search_exam] => 0 [search_subject] => 0 )
I am using urlencode() while preparing the search URL and urldecode() while reading the search URL
Problem
I am facing problems with some characters in the 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.
I want to allow all these characters. What could be the problem? How do I allow these? Please help Thanks, Sandeepan
Updates
Now only / character is causing URL breaking (404 error like before). So, I tried by removing the htaccess rewrite rule which hides the index.php in the URL and tried with complete URL instead. For a search term class/new
I tried with the following two URLs:-
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
And the first one works but the 2nd one does not. Notice the index.php?browse_by_exam
in the first one.
But I cant use the 1st URL convention. I have to make / work with index.php hidden. Please help
Thanks again Sandeepan
Edit (Solved)
Considering Bobince's answer to my other question
http://stackoverflow.com/questions/3235219/urlencoded-forward-slash-is-breaking-url
, I feel it is best to have URLs like this:-
http://project_name/browse_by_exam?type/tutor_search/keyword/class
%2Fnew/new_search/1/search_exam/0/search_subject/0
That way I get rid of the difficulty of readability caused by ¶m1=value1¶m2=value2
convention and also able to allow forward slashes in the query string part by using ?
I want to avoid AllowEncodedSlashes because Bobince said 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.