Thursday, June 29, 2017

.HTACCESS Redirection Issues

Leave a Comment

Namely, I have this .htaccess command...

RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([^\x00-\x7F]+).*$ ?open=encyclopedia&letter=$1&term=$0 [R,B,L,QSA] RewriteRule ^([A-Z](?:[^\x00-\x7F]+|[A-Z])?).*$ ?open=encyclopedia&letter=$1&term=$0 [R,B,L,QSA] 

...And I have two issues with it now:
Issue 1 - It loads shorthand of all of the letters except A, S and O. It displays blank white page instead of the actual page.
Issue 2 - When I enter http://example.com/Šandi (Astronomy), instead of redirecting me normally to http://example.com/?open=encyclopedia&letter=Š&term=Šandi+(Astronomy), the URL is http://example.com/?open=encyclopedia&letter=%25c5%25a0&term=%25c5%25a0andi+%2528Astronomy%2529

In other words:
• When I remove the [R] flag from either of the Rules, the shorthand URL (id est - example.com/A-O-S) is as described in Issue 1.
• When I add the [R] flag, it redirects inappropriately, as described in Issue 2, and it does not display the page.

Note: These problems include English and non-English letters (Š/Đ/Č/Ć/Ž).

As @anubhava suggested:
<?php print_r($_GET); ?> with [R] flag:
English: Array ( [open] => encyclopedia [letter] => V [term] => Vodolija (Astrologija) )
URL: ?open=encyclopedia&letterV&term=Vodolija (Astrologija)
Non-English: Array ( [open] => encyclopedia [letter] => ? [term] => Škorpija (Astrologija) )
URL: ?open=encyclopedia&letter=%c5&term=%c5%a0korpija%20(Astrologija)

<?php print_r($_GET); ?> without [R] flag:
English: Array ( [open] => encyclopedia [letter] => V [term] => Vodolija (Astrologija) )
URL: /Vodolija (Astrologija)
Non-English: Array ( [open] => encyclopedia [letter] => Š [term] => Škorpija (Astrologija) )
URL: /Škorpija (Astrologija)

As for the Index pages:
A - Array ( [open] => encyclopedia [letter] => A [term] => A ): It doesn't display the page, it shows blank white page.
O - Array ( [open] => encyclopedia [letter] => O [term] => O ): It doesn't display the page, it shows blank white page.
S - Array ( [open] => encyclopedia [letter] => S [term] => S ): It doesn't display the page, it shows blank white page.
As for the all the other Index pages, URL is Array ( [open] => encyclopedia [letter] => AnyLetter [term] => SameAnyLetter): It displays the page correctly... ...I do not see logic in it.

This is the new code:

RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] #1 RewriteRule ([A-Z](?:[^\x00-\xFF].|\w).*) ?open=encyclopedia&letter=$2 [R,B,NE,L,QSA] # it loads DZH, but not the rest #2 RewriteRule (([\x00-\xFF].|\w).*) ?open=encyclopedia&letter=$2 [R,B,NE,L,QSA] # it loads A-O-S and it loads DJ-ZH-LJ-NJ-SH RewriteRule ^([A-Z](?:[^\x00-\x7F]+|[A-Z])?).*$ ?open=encyclopedia&letter=$1&term=$0 [B,NE,L,QSA] 

When I delete the line #1, the line #2 is working fine. When I delete the line #2, the line #1 is working okay. But they won't work together. The line #2 displays all the letters except for the DŽ, and redirects properly. The line #1 displays only the letter DŽ properly, won't redirect and won't load the rest. With the line #2 enabled, the URL with /DŽ redirects to /?open=encyclopedia&letter=D%c5

UPDATE #6:

With the following code...

RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ((LJ).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] RewriteRule ((NJ).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] RewriteRule ((D\xC5\xBD).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] RewriteRule (([\x00-\xFF].|\w).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] 

...This happens:
• INDEX Pages: As for the „double-letter“ letters, it opens every letter correctly. As of the single letters, it loads every letter except A, O and S.
• TERM Pages: Considering it won't open A, O and S, therefore it won't open their Terms pages.
/Lav (Astrologija) doesn't redirect to /?open=encyclopedia&letter=L&term=Lav (Astrologija), but instead redirects to /?open=encyclopedia&letter=L&term=Lav+%2528Astrologija%2529 thus won't open the proper page.
• It opens properly and it redirects /Škorpija (Astrologija) properly to /?open=encyclopedia&letter=Š&term=Škorpija (Astrologija)
• It opens properly and it redirects /Đavo properly to /?open=encyclopedia&letter=Đ&term=Đavo
• Although it opens /U properly, /Unuk Al Haj redirects to /?open=encyclopedia&letter=Un&term=Unuk%20Al%20Haj, not opening the right page.
• Although it opens /U properly, /Ugaoni Razmak redirects to /?open=encyclopedia&letter=Ug&term=Unuk%20Al%20Haj, not opening the right page.
• Although it opens /R properly, /Ribe (Astrologija) redirects to /?open=encyclopedia&letter=Ri&term=Ribe (Astrologija), not opening the right page.
• Although it opens /V properly, /Vaga (Astrologija) redirects to /?open=encyclopedia&letter=Va&term=Vaga (Astrologija), not opening the right page.
• Although it opens /U properly, /Umerenost redirects to /?open=encyclopedia&letter=Um&term=Umerenost, not opening the right page.
• Although it opens /K properly, /Kuće (Astrologija) redirects to /?open=encyclopedia&letter=Ku&term=Kuće (Astrologija), not opening the right page.

2 Answers

Answers 1

It seems to me that you should be able to use:

RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L]  RewriteRule ^(.)[^/]*$ ?open=encyclopedia&letter=$1&term=$0 [L,QSA] 

Answers 2

Use NE (no escape) flag:

# here are all 2 letters which we count as 1  RewriteRule ((D\xC5\xBD).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] # C5 BD is utf8 encoding of Ž RewriteRule ((LJ).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] RewriteRule ((NJ).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA]  # one letter RewriteRule (([\x80-\xFF].|\w).*) ?open=encyclopedia&letter=$2&term=$1 [R,NE,L,QSA] 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment