How to pass Persian string as parameter in URL?


shafizadi

I have a URL like this:

www.example.com/ClassName/MethodName/Arg1/Arg2

Here is my .htaccessfile too:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

ErrorDocument 404 /error404.html

Here 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);
}

What's the problem now? Well, everything is fine..! It's perfectly fine for every URL route except when I use it مin the URL . ( مis Persian characters)

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 get a 404 Not Found page:

enter image description here


Well, I don't know where the problem is.. you know? How can I fix this? Is this an encoding issue? Otherwise what?

Note: I am using Xampp v3.2.1 (apache).


EDIT: As mentioned in the comments, I've added 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 points to a 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: Based on some testing, I identified the script that should be called by my rewrite rule ( index.php) , and it wasn't even called.


EDIT3: I have rewrite logging enabled on Apache, and when I checked the results, there was an interesting thing:

(These two examples are not related to the above examples)

Working route 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

doesn't work (redirects to 404 not found) Example:

[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 routed correctly, this Persian string will look like this: (decoding only):

%D8%B3%D9%84%D8%A7%D9%85

However, when the 404 route is not found, the Persian string will look like this:

\xd9\x86\xd8\xa8\xd9\x88\xd8\xaa

There seem to be two different encodings..

Bobbins

You can try this variant that works better:

RewriteRule ^([\s\S]*)$ index.php?rt=$1 [L,B,QSA]

The changes made are:

1: [\s\S]Used to match any character exactly, not .anything except a newline.

Although you generally don't want newlines ( ) in %0AURLs , I suspect Apache's regex matcher will treat your input path as ISO-8859-1 encoded.

IRI characters U+0645 Arabic letters مUTF-8-URL encoded as URI sequences %D9%85, while in ISO-8859-1 byte 0xD9 works fine, and 0x85 decodes as U+0085 next line (NEL), which is not Popular traditional control characters are usually counted as newlines. So if this happens, the expression .*will not match it.

Having said all that, it's quite theoretical since your example is the same for me, on my old XAMPP 1.8.2 on WinXP.

2: Use the [B] rewrite flag to ensure that all bytes are passed in the parameter in the correct URL-encoded form.

Otherwise, non-ASCII characters would break in the case of Apache sending the query string to PHP via Windows environment variables. The Windows environment is Unicode, so Apache has to decode the bytes when writing and PHP has to encode the bytes again when reading, unfortunately the encodings don't match.

Apache uses ISO-8859-1, PHP (via the C stdlib) uses the ANSI code page, depending on the Windows installed locale. In a Western installation you get code page 1252, which is close to ISO-8859-1, so only some bytes are wrong (again, that includes 0x85 in م); in other locales with other ANSI code pages, All non-ASCII characters will be completely wrong.

This doesn't necessarily apply to you, since XAMPP uses mod_php and doesn't need to use an environment to pass strings. But this will make a difference in other hosting environments. In any case, it will break the query parser if the URL special characters ("&" sign, plus sign, percent sign) in the string are not found.[B]

Related


How to pass Persian string as parameter in URL?

shafizadi I have a url like this: www.example.com/ClassName/MethodName/Arg1/Arg2 Here is my .htaccessfile too: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA] ErrorDocument

How to pass Persian string as parameter in URL?

shafizadi I have a URL like this: www.example.com/ClassName/MethodName/Arg1/Arg2 Here is my .htaccessfile too: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA] ErrorDocument

How to pass Persian string as parameter in URL?

shafizadi I have a URL like this: www.example.com/ClassName/MethodName/Arg1/Arg2 Here is my .htaccessfile too: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA] ErrorDocument

How to pass Persian string as parameter in URL?

shafizadi I have a URL like this: www.example.com/ClassName/MethodName/Arg1/Arg2 Here is my .htaccessfile too: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA] ErrorDocument

How to pass Persian string as parameter in URL?

shafizadi I have a URL like this: www.example.com/ClassName/MethodName/Arg1/Arg2 Here is my .htaccessfile too: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA] ErrorDocument

How to pass string in url parameter?

not any From API i get something like this: processId=22, now i want to pass it in url parameter but the problem is i need to pass key and value. How can i paste the whole string as parameter. Any suggestions? So what I want to achieve is: <a *ngIf="menu.refPa

How to pass string parameter to url in view?

Smith I have a url that takes any string as a parameter. When I redirect to that URL, I want to pass parameters inside the view. How do you do this in Django? I have urls defined like this: url(r'^user_view/(?P<service_name>.+)$', views.user_view, name='user_v

How to pass string parameter to url in view?

Smith I have a url that takes any string as a parameter. When I redirect to that URL, I want to pass parameters inside the view. How do you do this in Django? I have urls defined like this: url(r'^user_view/(?P<service_name>.+)$', views.user_view, name='user_v

How to pass string parameter to url in view?

Smith I have a url that takes any string as a parameter. When I redirect to this URL, I want to pass parameters inside the view. How do you do this in Django? I have urls defined like this: url(r'^user_view/(?P<service_name>.+)$', views.user_view, name='user_v

Pass parameter string in url string

username my variable: var strArgsString = "?Category=Customer&Year=2014"; var intModuleNo = "2"; var strOrigDashName = "Invoices" My AJAX post: var jqxhr = $.post("includes/saveParameters.asp?dname="+strOrigDashName+"&mod="+intModuleNo+"&args='"+strArgsSt

Pass parameter string in url string

username my variable: var strArgsString = "?Category=Customer&Year=2014"; var intModuleNo = "2"; var strOrigDashName = "Invoices" My AJAX post: var jqxhr = $.post("includes/saveParameters.asp?dname="+strOrigDashName+"&mod="+intModuleNo+"&args='"+strArgsSt

How to pass link as parameter in URL

Asan Malik I want to pass a domain link with http or https protocol as a parameter in the link like http://www.payskip.me/url.php?go=https://www.oast.com The problem is when i pass the link without .com or any other extension it works as if i passed http://www

How to pass url parameter to templateUrl

json2031 I'm using angular ui-router to retrieve the page, but in the documentation it only shows how to pass parameters in the url, not in the template url. Is there anyway to pass it in templateUrl? Below is my code <div ui-view></div> <!-- We'll also add

How to pass link as parameter in URL

Asan Malik I want to pass a domain link with http or https protocol as a parameter in the link like http://www.payskip.me/url.php?go=https://www.oast.com The problem is when i pass the link without .com or any other extension it works as if i passed http://www

How to pass link as parameter in URL

Asan Malik I want to pass a domain link with http or https protocol as a parameter in the link like http://www.payskip.me/url.php?go=https://www.oast.com The problem is when i pass the link without .com or any other extension it works as if i passed http://www

How to pass link as parameter in URL

Asan Malik I want to pass a domain link with http or https protocol as a parameter in the link like http://www.payskip.me/url.php?go=https://www.oast.com The problem is when i pass the link without .com or any other extension it works as if i passed http://www

How to pass link as parameter in URL

Asan Malik I want to pass a domain link with http or https protocol as a parameter in the link like http://www.payskip.me/url.php?go=https://www.oast.com The problem is when i pass the link without .com or any other extension it works as if i passed http://www

How to detect persian characters in a string

Soheila Tarigi I have a string value that contains many different characters, and I want to get a string that contains allowed characters. For example: I have this string "geeks01 $سهیلاطریقی03.02 geeks!@!!". But I want to return this value: "0103.سهیلاطریقی02

How to detect persian characters in a string

Soheila Tarigi I have a string value that contains many different characters, and I want to get a string that contains allowed characters. For example: I have this string "geeks01 $سهیلاطریقی03.02 geeks!@!!". But I want to return this value: "0103.سهیلاطریقی02

How to determine if a string is English or Persian?

Saeed Hashemi I have an edittext of a form, and when the user enters text into the edittext, I want the program to detect which language the edittext is inserted in. Is there a way to determine if a string is English or Persian? I found this arabic code public

How to detect persian characters in a string

Soheila Tarigi I have a string value that contains many different characters, and I want to get a string that contains allowed characters. For example: I have this string "geeks01 $سهیلاطریقی03.02 geeks!@!!". But I want to return this value: "0103.سهیلاطریقی02

How to detect persian characters in a string

Soheila Tarigi I have a string value that contains many different characters, and I want to get a string that contains allowed characters. For example: I have this string "geeks01 $سهیلاطریقی03.02 geeks!@!!". But I want to return this value: "0103.سهیلاطریقی02

How to detect persian characters in a string

Soheila Tarigi I have a string value that contains many different characters, and I want to get a string that contains allowed characters. For example: I have this string "geeks01 $سهیلاطریقی03.02 geeks!@!!". But I want to return this value: "0103.سهیلاطریقی02

How to detect persian characters in a string

Soheila Tarigi I have a string value that contains many different characters, and I want to get a string that contains allowed characters. For example: I have this string "geeks01 $سهیلاطریقی03.02 geeks!@!!". But I want to return this value: "0103.سهیلاطریقی02

How to determine if a string is English or Persian?

Saeed Hashemi I have an edittext of a form, and when the user enters text into the edittext, I want the program to detect which language the edittext is inserted in. Is there a way to determine if a string is English or Persian? I found this arabic code public