2

If the article title in URL is written in full English, then everything is displayed correctly. However if the title is written in Greek, I get a 404 page. Without using the htaccess rewrite rule, it displays the page.

My question is how can I make it work with the htaccess?

htaccess error when dealing with RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/([a-zA-Z0-9]+)/?$ article.php?title=$1 [NC,QSA,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]

3 scenarios:

First (english chars):

title: hello
url: example.com/article/hello
OPENS THE PAGE

Second (greek chars):

title: γειά
url: example.com/article/γειά
The requested URL article/γειά.php was not found on this server.

Third (without using the htaccess):

/article.php?title=γειά
OPENS THE PAGE

2 Answers 2

0

[a-zA-Z0-9] will match only english text and numbers.

Change your article rewrite rule to:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([^/]+)/?$ index.php?title=$1 [NC,QSA,L]

[^/]+ will match 1 and more of any character till next / is matched or end of string is reached thus matching non-english characters.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you, that worked! Please tell me, is there any way to not have %20 in the urls but lets say - ?
To convert space to hyphen you need a separate rule. See this answer for that
I don't really get how it works. Should I write in the url example.com/article/this is an article and it will keep it as is ?
First of all this question is about supporting greek characters so we should stick with this if possible. Now other rules are for translating space to hyphen and those rules need be placed just below RewriteEngine On line.
Unfortunately not... I cant make it work but I am accepting your answer. Thank you
|
0

Try:

RewriteRule ^article/(.*)/?$ article.php?title=$1 [NC,QSA,L]

This would allow any inputs for the "title" parameter, which should pass for any inputs.

2 Comments

Thank you, that worked! Please tell me, is there any way to not have %20 in the urls but lets say -
See anubhava's reply on his answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.