Apache and Japanase website re-write module - apache

I use to work on a multilingual website, within the next few months, we added Korean and we are now adding Japanese. Apart the fact that it generate a huge list of 404 errors on the logs files, I am having another issue with the urls. The Apache server response with a Bad request when I insert this url:
学校-詳細な評価-11
#[.htaccess]
RewriteRule ^学校-詳細な評価-(.+)$ /statistics.php?n=$1 [L]
I tried also using the [B] flag, but nothing changes.
I tried as well to remove character and I found that it only works if I do in this way:
#[.htaccess]
RewriteRule ^学-(.+)$ /statistics.php?n=$1 [L]
But of course I cannot avoid the issue in this way :D
I notice that Apache will convert the url to:
%E5%AD%A6%E6%A0%A1-%E8%A9%B3%E7%B4%B0%E3%81%AA%E8%A9%95%E4%BE%A1-11
Then I tried it as well:
#[.htaccess]
RewriteRule ^%E5%AD%A6%E6%A0%A1-%E8%A9%B3%E7%B4%B0%E3%81%AA%E8%A9%95%E4%BE%A1-(.+)$ /statistics.php?n=$1 [L]
But I'm still having the issue :(
Does anyone know how to fix it or why this is happening? I did a research but all forums and website only suggest to use the flag B at the end of the url.
Any help is welcome! Thank you :)

Try in Hex:
RewriteRule ^\xE5\xAD\xA6\xE6\xA0\xA1-\xE8\xA9\xB3\xE7\xB4\xB0\xE3\x81\xAA\xE8\xA9\x95\xE4\‌​xBE\xA1-(.+)$ /statistics.php?n=$1 [L]
For example with having this rule:
RewriteRule ^\xE5\xAD\xA6-(.+)$ /statistics.php [L]
this url http://domain.com/学-t will redirect to http://domain.com/statistics.php
For testing you can use online htaccess tester: http://htaccess.madewithlove.be/ and remember to change the page encoding to UTF-8 before testing.

Related

.htaccess -> Characters not escaping in rewrite string "(" ")"

I'm currently trying to add some redirects from a very old site that had PDFs and some of these PDFs have used brackets to contain the years.
For example:
/document%2070C11-name%20(2012).pdf
So the full URL I am trying to redirect is:
https://website.co.uk/document/1/document%2070C11-name%20(2012).pdf
I have previously setup many different redirects on this site but ones with the special characters seem to be causing an issue.
Here is the examples of what I have tried, and failed with so far:
RewriteEngine on
RewriteBase /
RewriteRule ^document/1/document%2070C11-name%20\(2008\).pdf$ document/newurl/ [R=301,L]
RewriteRule ^document/1/document%2070C11-name%20(.*)2008(.*).pdf$ document/newurl/ [R=301,L]
So I tried escaping the character and just trying a wildcard. Neither seemed to work on my Apache server. The code I used did seem to work when I tested it on:
http://htaccess.madewithlove.be/
But I am pretty stuck now and would love any help I can get.
Thanks,
Kane
To match %MN character in URL, you need to use \xMN in the RewriteRule pattern.
Hence this rule should work for you:
RewriteRule ^document/1/document\x2070C11-name\x20\(2008\)\.pdf$ /document/newurl/ [R=301,NC,NE,L]
This will redirect https://website.co.uk/document/1/document%2070C11-name%20(2008).pdf to https://website.co.uk/document/newurl/

htaccess redirect without .php extension

I recently changed a directory /old_dir/ to be /new_dir/ using this:
RedirectMatch 301 /old_dir/(.*) /new_dir/$1
Which seems to be working perfect for the url:
http://www.mysite.com/old_dir/test.php?var=xxxx
goes to
http://www.mysite.com/new_dir/test.php?var=xxxx
where test.php is the filename. But in many places I use:
http://www.mysite.com/old_dir/test?var=xxxx
which comes up with:
The requested URL /old_dir/test was not found on this server.
not using the .php extension takes advantage of some sort of apache plugin that knows it's a php handler, which seemingly messes up redirect because it says it doesn't exist now.
I am not sure how to fix this issue.
Edit: All the solutions are for this special case, but note that i have about 1000 other files that may not be php, or named the same.
For right now I just made a symbolic link in the old_dir with the name "test" to point to the new_dir's test.php. But I am still looking for a non-specific solution that includes my scenario.
Have you ever tried using mod_rewrite?
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$ $1/$2.php [QSA]
RewriteRule ^old_dir/([^/]+)/$ new_dir/$1.php [QSA]

Writing htaccess that reroutes to other folder

I'm trying to write a rule that redirects a request to a different file/path. Here is a sample of the incoming URL: /js/library/sample.js, has to reroute to /private/package/library/js/sample.js.
I tried:
ReWriteCond ^/js/(A-Za-z_]+)$/(A-Za-z.]+)$ /private/package/$1/js/$2
I'm finding it difficult to write the rule correctly though.
Thanks.
PS. Any good htaccess/rejex tutorials, send them along.
Do this:
RewriteRule ^(js)/([\w]+)/([\w.]+)/?$ /private/package/$2/$1/$3 [NC,L]
I found these Apache docs sufficient to learn.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.0/rewrite/

htaccess rewrite hide .php and also flatten query string on one particular url

I have checked various topics and nothing caught my eyes. This is what am trying to do ..
It's a small site and with only few pages all in my root /mobile folder. So I decided to modify h*p://example.com/mobile/academics.php to h*p://example.com/mobile/academics (without the trailing slash)
RewriteRule ^([^.]+)$ $1.php [NC,L] - Works fine.
But I have http://example.com/mobile/program.php?p=ams which I want to convert as http://example.com/mobile/program/ams . I tried this :
RewriteRule ^/program/([^/]+)$ program.php?p=$1 - Makes no effect. Browser keeps looking for /program/ams.php
How to have both rules coexist? I have query string only on program.php . Any help is appreciated. I am sorry if this has been answered before. I searched for quite sometime and couldn't find any.
Thanks,
Vik
use
RewriteRule ^/?program/([^/]+)$ program.php?p=$1

Using .htaccess mod_rewrite to pass all URLs in a given directory to a single redirect script

Im trying to use mod_rewrite to redirect any call to /real-estate/* to rewrite.php...i know i can redirect everything to rewrite.php with this:
RewriteRule ^(.*)$ rewrite.php?url=$1 [L]
I would like to have my urls formatted like /real-estate/12345/123-anywhere-st ....where the 123-anywhere-st would be ignored, and have /real-estate/12345 sent to rewrite.php...id like the rewrite rule to only be used on /real-estate...all other areas of the site should function as is...Ive searched all over for a good tutorial or cheat sheet, but none that I can find actually explain how to format the mod_rewrite rules, they just give one or two examples and thats it...can anyone help, as well as maybe provide a link to somewhere I can learn
Thanks!
RewriteRule ^/real-estate/(.*)$ rewrite.php?url=$1 [L]