I am running the official docker php image: php:7.4-apache
Some URLs are not correctly being rewritten. We are seeing IPs in some links in the docker container but not when we test locally in MAMP.
These are the types of rewrites we are doing in the htaccess file :
RewriteRule ^gift-cards/(.*)$ http://34.245.51.253/gift-cards/$1 [P]
### Redirect for merchants pages
RewriteRule ^merchants/(.*)$ http://34.245.51.253/merchants/$1 [P]
The logs are showing:
[Mon Nov 14 12:00:14.313116 2022] [proxy:debug] [pid 26] mod_proxy.c(1503): [client 172.17.0.1:56704] AH01143: Running scheme http handler (attempt 0)
[Mon Nov 14 12:00:14.316758 2022] [proxy_ajp:debug] [pid 26] mod_proxy_ajp.c(769): [client 172.17.0.1:56704] AH00894: declining URL http://34.245.51.253/
I can see a similar question here AH00894: declining URL fcgi
But the container isn't running PHP FPM so I am not sure how to proceed?
Everything is going perfect. It looks like it understands what I want, but then something I can't understand begins to happen. My .htaccess looks like this:
RewriteEngine On
RewriteBase "/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^contacts/edit(new|existing)$ /index.php?route=contacts/edit$1 [NC,L,QSA]
The first relevant line in the log is ->
[Wed Apr 07 14:23:41.495232 2021] [rewrite:trace2] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 - - [localhost/sid#209cc4c8][rid#23090058/initial] [perdir /path/to/document/root/] rewrite 'contacts/editNew' -> '/index.php?route=contacts/editNew', referer: http://localhost/
Comment: It looks at the request URI and attempts to substitute it to 'index.php?route=...'
Line #2 ->
[Wed Apr 07 14:23:41.495256 2021] [rewrite:trace3] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 - - [localhost/sid#209cc4c8][rid#23090058/initial] split uri=/index.php?route=contacts/editNew -> uri=/index.php, args=route=contacts/editNew, referer: http://localhost/
Comment: It tries to split the uri into URI and parameters.
Line #3 ->
[Wed Apr 07 14:23:41.495283 2021] [rewrite:trace2] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 - - [localhost/sid#209cc4c8][rid#23090058/initial] [perdir /document/root/path/] trying to replace prefix /path/to/document/root/ with /, referer: http://localhost/
Comment: mod_rewrite just translates the DOCUMENT_ROOT path to "/".
Line #4 ->
[Wed Apr 07 14:23:41.495311 2021] [rewrite:trace2] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 - - [localhost/sid#209cc4c8][rid#23090058/initial] [perdir /path/to/document/root/] trying to replace context docroot /path/to/document/root with context prefix , referer: http://localhost/
Comment: I do not know what this is. I would like someone to, please, explain what is going on in this line. Strangely, there is a space between prefix and the comma. Does this mean anything?
Line #5 ->
[Wed Apr 07 14:23:41.495334 2021] [rewrite:trace1] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 - - [localhost/sid#209cc4c8][rid#23090058/initial] [perdir /path/to/document/root/] internal redirect with /index.php [INTERNAL REDIRECT], referer: http://localhost/
Comment: This is the redirect to /index.php, which I believe is correct.
Line #6 ->
[Wed Apr 07 14:23:41.495834 2021] [rewrite:trace3] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 - - [localhost/sid#209cc4c8][rid#23091b18/initial/redir#1] [perdir /path/to/document/root/] strip per-dir prefix: /path/to/document/root/index.php -> index.php, referer: http://localhost/
Comment: I believe this is taking an absolute URL path and making it relative. Is this standard? Do you have to specify this in your code or does it happen by default?
Line #7 ->
[Wed Apr 07 14:23:41.495900 2021] [rewrite:trace3] [pid 2302] mod_rewrite.c(483): [client ::1:13883] ::1 r- - [localhost/sid#209cc4c8][rid#23091b18/initial/redir#1] [perdir /path/to/document/root/] applying pattern '^contacts/edit(new|existing)$' to uri 'index.php', referer: http://localhost/
Comment: This is what has got me puzzled. '^contacts/edit(edit|existing)$' is applied to uri 'index.php', but not to 'index.php?route=contacts/edit$1', which is what, I believe, I have indicated in my second rewrite rule. So, why doesn't this occur??
Finally, and I have no idea why this happens, the entire URL gets translated to "http://contacts/editnew"! Even localhost gets removed.
I would really appreciate if you could help me out with this.
Don't flag this as a duplicate unless you know what you are doing. Some questions look similar, but aren't what I'm looking for.
If a user hits example.com/friendly-folder it should be internally redirected to example.com/system-folder.
However if a user hits the old example.com/system-folder it should be externally redirected to the new name example.com/friendly-folder.
So, basically, the directory URL must always be friendly, but pointing to the old one. I believe if I just made two rules without any condition it would get stuck in an infinite loop.
I've tried this in my .htaccess
RewriteRule ^friendly-folder(.*)$ system-folder$1 [NC,L]
RewriteCond %{THE_REQUEST} ^GET\ /system-folder
RewriteRule ^system-folder(.*)$ /friendly-folder$1 [R=301,NC,L]
Which effectively internally redirects from the friendly folder to the system one, but doesn't externally redirect from the system folder to the friendly one.
Any ideas? While you are at it, if you have a method that also works for redirecting and rewriting files it would be much appreciated.
Update
Now i've tried this configuration:
RewriteRule ^friendly-folder(.*)$ system-folder$1 [NC,END]
RewriteRule ^system-folder(.*)$ friendly-folder$1 [R=301,NC,L]
And I'm getting this error log:
[Sun Jan 15 18:40:49.765190 2017] [rewrite:trace3] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] strip per-dir prefix: C:/xampp/htdocs/urls/system-folder/ -> system-folder/
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace3] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] applying pattern '^friendly-folder(.*)$' to uri 'system-folder/'
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace3] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] strip per-dir prefix: C:/xampp/htdocs/urls/system-folder/ -> system-folder/
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace3] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] applying pattern '^system-folder(.*)$' to uri 'system-folder/'
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace2] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] rewrite 'system-folder/' -> 'friendly-folder/'
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace3] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] add per-dir prefix: friendly-folder/ -> C:/xampp/htdocs/urls/friendly-folder/
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace2] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] explicitly forcing redirect with http://localhost/C:/xampp/htdocs/urls/friendly-folder/
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace1] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] escaping http://localhost/C:/xampp/htdocs/urls/friendly-folder/ for redirect
[Sun Jan 15 18:40:49.765691 2017] [rewrite:trace1] [pid 3936:tid 1896] mod_rewrite.c(477): [client ::1:50822] ::1 - - [localhost/sid#a92bb8][rid#2a52150/initial] [perdir C:/xampp/htdocs/urls/] redirect to http://localhost/C:/xampp/htdocs/urls/friendly-folder/ [REDIRECT/301]
[Sun Jan 15 18:40:49.771194 2017] [core:error] [pid 3936:tid 1896] (20023)The given path was above the root path: [client ::1:50822] AH00127: Cannot map GET /C:/xampp/htdocs/urls/friendly-folder/ HTTP/1.1 to file
I have a XAMPP Apache server, and have added a configuration file to rewrite URLs with a trailing slash and redirect to their slash-less counterparts.
Therefore, a url like http://example.com/the-audio/ gets redirected to http://example.com/the-audio. The problem is, it's not working when the directory name is only one word.
So, http://example.com/audio/ does not get it's slash removed. This is really strange for me, and checking the logs it appears as though the rule isn't matched in this case.
Here's my rule (only one in the file)
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)\/+$
RewriteRule ^ %1 [R=301,L]
And this is the error dump
error.log
[Wed Jan 11 22:13:32.729812 2017] [rewrite:trace3] [pid 1688:tid 1904] mod_rewrite.c(477): [client ::1:52432] ::1 - - [localhost/sid#ba8340][rid#29a2190/initial] [perdir C:/xampp/htdocs/tecnoedu/] strip per-dir prefix: C:/xampp/htdocs/tecnoedu/audio/ -> audio/
[Wed Jan 11 22:13:32.730312 2017] [rewrite:trace3] [pid 1688:tid 1904] mod_rewrite.c(477): [client ::1:52432] ::1 - - [localhost/sid#ba8340][rid#29a2190/initial] [perdir C:/xampp/htdocs/tecnoedu/] applying pattern '^' to uri 'audio/'
[Wed Jan 11 22:13:32.730312 2017] [rewrite:trace1] [pid 1688:tid 1904] mod_rewrite.c(477): [client ::1:52432] ::1 - - [localhost/sid#ba8340][rid#29a2190/initial] [perdir C:/xampp/htdocs/tecnoedu/] pass through C:/xampp/htdocs/tecnoedu/audio/
[Wed Jan 11 22:13:32.730312 2017] [rewrite:trace1] [pid 1688:tid 1904] mod_rewrite.c(477): [client ::1:52432] ::1 - - [localhost/sid#ba8340][rid#33046a0/subreq] [perdir C:/xampp/htdocs/tecnoedu/] pass through C:/xampp/htdocs/tecnoedu/audio/index.php
Thanks in advance!
According to your log /audio/ is an existing directory. So your rule wouldn't run since the first condition stops it running on existing directories. Remove the first condition to resolve it.
Also, to do this on existing directories, you will need to turn DirectorySlash off, or the server will add the slash back in itself. Note that there is some security concern with that.
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/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa, 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/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa -> islamic_sources/sahifeh_sajadiyeh/1580/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa, 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/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa', 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/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa' -> 'index.php?rt=islamic_sources/sahifeh_sajadiyeh/1580/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa', 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/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa -> uri=index.php, args=rt=islamic_sources/sahifeh_sajadiyeh/1580/\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa, 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/\xd9\x85\xd8\xa8
[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/\xd9\x85\xd8\xa8 -> islamic_sources/sahifeh_sajadiyeh/306/\xd9\x85\xd8\xa8
[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/\xd9\x85\xd8\xa8'
[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:
\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa
Seems there is two different kinds of encoding ..
You could try this variant that may work better:
RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]
The changes that this makes are:
1: using [\s\S] to match absolutely any character, instead of . which matches anything but a newline.
Though you wouldn't normally expect newline (%0A) to be in your URLs, my suspicion is that Apache's regexp matcher is treating your input path as being in the ISO-8859-1 encoding.
The IRI character U+0645 Arabic Letter Meem م UTF-8-URL-encodes to URI sequence %D9%85, and whilst byte 0xD9 is okay in ISO-8859-1, 0x85 decodes to U+0085 Next Line (NEL), an undesirable legacy control character that often counts as a newline. So if that happened, the expression .* wouldn't match it.
Having said all that, this is quite theoretical as your example works as-is for me, on an old XAMPP 1.8.2 I had lying about on WinXP.
2: using the [B] rewrite flag, to ensure all bytes are passed in correctly-URL-encoded form in the parameter.
Otherwise, non-ASCII characters would break for situations where Apache sends the query string to PHP through Windows environment variables. The Windows environment is Unicode, so Apache has to decode the bytes on writing and PHP has to encode them again on reading, and unfortunately those encodings don't match.
Apache uses ISO-8859-1 and PHP (via C stdlib) uses the ANSI code page, which depends on the locale of the Windows installation. On a Western install, you get code page 1252, which is close to ISO-8859-1 so only some of the bytes will be wrong (again, this includes the 0x85 in م); on other locales with other ANSI code pages all the non-ASCII characters will be wildly wrong.
This doesn't necessarily apply to you as XAMPP is using mod_php, which doesn't need to use the environment to pass strings. But it would make a difference in other hosting environments. In any case, without [B] you'll find URL-special characters in the string (ampersand, plus, percent) break the query parser.
Use URL encoder:
String encodedURL = "www.example.com/ClassName/Methodname/254/" + URLEncoder.encode("Any text in any language", "utf-8");
UTF-8 of course is the encoding to use.
You can read more here: https://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html