I have a URL like this pattern:
www.example.com/ClassName/MethodName/Arg1/Arg2
Also here is my .htaccess
file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
ErrorDocument 404 /error404.html
And this is my routing system:
if (empty($_GET['rt'])) {
require_once('application/home.php');
} else {
require_once('application/search.php');
$url = rtrim ($_GET['rt'], '/');
$url = explode('/', $url);
$ClassName = array_shift($url);
$MethodName = array_shift($url);
$Arg1 = array_shift($url);
$Arg2 = array_shift($url);
}
Now what is the problem? Well, Everything is fine ..! Routing is completely fine for every URLs except when I use ?
in the URL. (?
is a Persian character)
For e.g.
www.example.com/ClassName/Methodname/124/??? ??? // it is fine
www.example.com/ClassName/Methodname/254/???? ?? // it isn't fine
// because there is ? ^ in the URL
So when I use ?
in the URL, I will faced with 404 Not Found page:
Well, I don't know that problem comes from where .. do you know? And how can I fix it? Is it a encoding issue? Or what?
Note: I use Xampp v3.2.1 (apache).
EDIT: As mentioned in the comment, I add these two examples:
<?php
$str = "www.example.com/ClassName/Methodname/124/??? ???";
$url = explode('/', $str);
echo "<pre>";
print_r($url);
/*
Array
(
[0] => www.example.com
[1] => ClassName
[2] => Methodname
[3] => 124
[4] => ??? ???
)
*/
Two: (this directs to 404 Not Found)
<?php
$str = "www.example.com/ClassName/Methodname/254/???? ??";
$url = explode('/', $str);
echo "<pre>";
print_r($url);
/*
Array
(
[0] => www.example.com
[1] => ClassName
[2] => Methodname
[3] => 254
[4] => ???? ??
)
*/
EDIT2: According to a few tests, I figured out the script that should get called by my rewriting rules (index.php
), it even doesn't get call.
EDIT3: I enabled rewrite logging on Apache and when I check the result, there is a interesting thing:
(These two samples aren't related to the above examples)
Working routing sample:
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] add path info postfix: C:/xampp/htdocs/myweb/islamic_sources -> C:/xampp/htdocs/myweb/islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] strip per-dir prefix: C:/xampp/htdocs/myweb/islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa -> islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] applying pattern '^(.*)$' to uri 'islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa', referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace4] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] RewriteCond: input='C:/xampp/htdocs/myweb/islamic_sources' pattern='!-f' => matched, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace4] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] RewriteCond: input='C:/xampp/htdocs/myweb/islamic_sources' pattern='!-d' => matched, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace2] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] rewrite 'islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa' -> 'index.php?rt=islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa', referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.276918 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] split uri=index.php?rt=islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa -> uri=index.php, args=rt=islamic_sources/sahifeh_sajadiyeh/1580/xd9x86xd8xa8xd9x88xd8xaa, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] add per-dir prefix: index.php -> C:/xampp/htdocs/myweb/index.php, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace2] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] strip document_root prefix: C:/xampp/htdocs/myweb/index.php -> /myweb/index.php, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace1] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#28661a0/initial] [perdir C:/xampp/htdocs/myweb/] internal redirect with /myweb/index.php [INTERNAL REDIRECT], referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c8b0/initial/redir#1] [perdir C:/xampp/htdocs/myweb/] strip per-dir prefix: C:/xampp/htdocs/myweb/index.php -> index.php, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c8b0/initial/redir#1] [perdir C:/xampp/htdocs/myweb/] applying pattern '^(.*)$' to uri 'index.php', referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace4] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c8b0/initial/redir#1] [perdir C:/xampp/htdocs/myweb/] RewriteCond: input='C:/xampp/htdocs/myweb/index.php' pattern='!-f' => not-matched, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.277919 2016] [rewrite:trace1] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c8b0/initial/redir#1] [perdir C:/xampp/htdocs/myweb/] pass through C:/xampp/htdocs/myweb/index.php, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.470250 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c1b8/initial] [perdir C:/xampp/htdocs/myweb/] strip per-dir prefix: C:/xampp/htdocs/myweb/fonts/taha/QuranTaha.woff -> fonts/taha/QuranTaha.woff, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.470250 2016] [rewrite:trace3] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c1b8/initial] [perdir C:/xampp/htdocs/myweb/] applying pattern '^(.*)$' to uri 'fonts/taha/QuranTaha.woff', referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.470250 2016] [rewrite:trace4] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c1b8/initial] [perdir C:/xampp/htdocs/myweb/] RewriteCond: input='C:/xampp/htdocs/myweb/fonts/taha/QuranTaha.woff' pattern='!-f' => not-matched, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
[Sat Jan 02 22:17:00.470250 2016] [rewrite:trace1] [pid 3188:tid 1728] mod_rewrite.c(475): [client ::1:49413] ::1 - - [localhost/sid#c397b0][rid#286c1b8/initial] [perdir C:/xampp/htdocs/myweb/] pass through C:/xampp/htdocs/myweb/fonts/taha/QuranTaha.woff, referer: http://localhost/myweb/search?s=islamic_sources&q=%D8%B3%D9%84%D8%A7%D9%85
Not working (redirects to 404 not found) sample:
[Sat Jan 02 22:07:09.734092 2016] [rewrite:trace3] [pid 3188:tid 1712] mod_rewrite.c(475): [client ::1:64955] ::1 - - [localhost/sid#c397b0][rid#83ec138/initial] [perdir C:/xampp/htdocs/myweb/] add path info postfix: C:/xampp/htdocs/myweb/islamic_sources -> C:/xampp/htdocs/myweb/islamic_sources/sahifeh_sajadiyeh/306/xd9x85xd8xa8
[Sat Jan 02 22:07:09.734092 2016] [rewrite:trace3] [pid 3188:tid 1712] mod_rewrite.c(475): [client ::1:64955] ::1 - - [localhost/sid#c397b0][rid#83ec138/initial] [perdir C:/xampp/htdocs/myweb/] strip per-dir prefix: C:/xampp/htdocs/myweb/islamic_sources/sahifeh_sajadiyeh/306/xd9x85xd8xa8 -> islamic_sources/sahifeh_sajadiyeh/306/xd9x85xd8xa8
[Sat Jan 02 22:07:09.734092 2016] [rewrite:trace3] [pid 3188:tid 1712] mod_rewrite.c(475): [client ::1:64955] ::1 - - [localhost/sid#c397b0][rid#83ec138/initial] [perdir C:/xampp/htdocs/myweb/] applying pattern '^(.*)$' to uri 'islamic_sources/sahifeh_sajadiyeh/306/xd9x85xd8xa8'
[Sat Jan 02 22:07:09.734092 2016] [rewrite:trace1] [pid 3188:tid 1712] mod_rewrite.c(475): [client ::1:64955] ::1 - - [localhost/sid#c397b0][rid#83ec138/initial] [perdir C:/xampp/htdocs/myweb/] pass through C:/xampp/htdocs/myweb/islamic_sources
Interesting point: when routing is fine, that Persian string will be like this: (just decode):
%D8%B3%D9%84%D8%A7%D9%85
But when routing is 404 not found, the Persian string will be like this:
xd9x86xd8xa8xd9x88xd8xaa
Seems there is two different kinds of encoding ..
See Question&Answers more detail:
os