Jump to content
Erbenos

404 not working for unicode URL

Recommended Posts

Hello,

I encountered interesting behaviour yesterday.

I have custom module, which serves as 404 redirect which works like this: 

$this->addHookAfter("ProcessPageView::pageNotFound", $this, "hook404Page");

And in hook404Page function I return 404 page.

The problem is while this does work for:

http://testsite.dev/nonpage

It doesn't work for non standard URL like these:

http://testsite.dev/něnpage

Any idea why? Thanks.

Edited by Erbenos
English is hard

Share this post


Link to post
Share on other sites

You need to enable UTF8 URIs in your htaccess file. I assume you are using ProcessWire 2.8 or 3.0, and so you can simply comment out rule 16a and uncomment rule 16b (if I'm not mistaken). This should enable the URIs you would like to use.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you, but that didn't fix it for me. I chanched htaccess, restarted Apache and nothing changed.

Share this post


Link to post
Share on other sites
7 hours ago, Erbenos said:

Thank you, but that didn't fix it for me. I chanched htaccess, restarted Apache and nothing changed.

Just to confirm did you uncomment this rule?

RewriteCond %{REQUEST_URI} "^/~?[-_./a-zA-Z0-9æåäßöüđжхцчшщюяàáâèéëêěìíïîõòóôøùúûůñçčćďĺľńňŕřšťýžабвгдеёзийклмнопрстуфыэęąśłżź]*$"

Also, you don't need to restart Apache when changing htaccess files; you only need to restart if you have changed a configuration file, such as httpd.conf or a virtual host file.

  • Like 1

Share this post


Link to post
Share on other sites

Then I'm afraid I'm not sure what the problem is. I use the same hook and rul 16b for Jumplinks 2, and it works. Is your specific problem that your hook404Page method doesn't get triggered at all?

Share this post


Link to post
Share on other sites

Could it be that the .htaccess file got convert to an ISO encoding?

Share this post


Link to post
Share on other sites

I actually use your jumplinks plugin for redirecting old rules to the new ones. As @BitPoet said, I ll check encoding and will come back with an answer. Thanks everyone.

Update: File is in UTF-8

Share this post


Link to post
Share on other sites

Whoa... this is kind of funny. There is setting specifically for what I want just below:

 

# -----------------------------------------------------------------------------------------------
  # 14. OPTIONAL: Send URLs with non-ASCII name-format characters to 404 page (optimization)
  # -----------------------------------------------------------------------------------------------

  RewriteCond %{REQUEST_URI} "[^-_.a-zA-Z0-9/~]"
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?it=/http404/ [L,QSA]

One may wonder how does he have utf8 page names and correct 404 redirects but oh well, this is just what i needed.

Share this post


Link to post
Share on other sites

Yep, but I dont actually use utf-8 addresses, I just needed to redirect them to 404, because without this option, it wasn't working.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...