WPML › Subcategory pages generates 404 ‹ WordPress WPML › Subcategory pages generates 404 ‹ WordPress wordpress wordpress

WPML › Subcategory pages generates 404 ‹ WordPress


PLEASE CHECK THE UPDATE BELOW.

The solution to this problem is in your Apache configuration. You need to alter the regular expression that turns paths into parameters for WordPress's index.php file.

WordPress is a very high-level system working on PHP which itself is a very high level system too. WordPress does not have access to urls as they reach to server. It only has its index.php file and it needs requests to come to this file so it can handle the request.

To make this possible, they use mod_rewrite, an Apache module which modifies requests before server decides what to do with the request.

Please check your server's error logs. You will see the real files the server tried to access. Also, please check .htaccess files WordPress created in folders. In these files, you will see regular expressions that mod_rewrite uses.

I have checked your blog and it looks like you have already solved this. I still wanted to write so others having the same issue can benefit. Especially after seeing your mention of another post at somewhere else from two years ago being unsolved.

UPDATE:

I am glad that I had told that "I am almost sure..." :D (referring to comments to this answer) It looks like things are a little different than the situation I solved a few years ago.

I have checked WordPress code and made some trials. I had originally thought that WordPress cannot find the article because of /en/ however I was wrong. The default behavior of WordPress to find a post from a url covers the situation as a kind-of-positive side effect: Let's say I do not have any plugins, or any language so /en/ means nothing to WordPress.

When I want to browse to erik.landvall.se/en/ it returns 404 as expected. However, if we have a category structure as abc/cde/efg/ and an article as moo which can be accessed at abc/cde/efg/moo; when I alter the category part of the link, WordPress automatically redirects me to abc/cde/efg/moo:

en/abc/cde/efg/mooabc/efg/moocde/efg/moo...

all redirects to abc/cde/efg/moo. At your blog, I have seen the same behavior except for en/ which brings your plugins into the scene. It is now obvious that plugin handles url structure in a different way than WordPress originally does or causes change in the original behavior in another way.

I wanted to check plugin source as I promised; but I saw that it is not possible for me now, because it is a product I have to purchase to be able to see the source and I am not willing to buy something which I will never use :)

Since you said "In the parent category I can still see the post and navigate to it without a problem." I thought removing subcategories from url. This is a pretty dirty hack; but better than editing the plugin.

We put this ugly php file, fix_lang_subcategory.php, to our root folder:

<?phpfunction fix_lang_subcategory() {    $p = trim($_SERVER['REDIRECT_URL'], '/');    if (substr_count($p, '/') > 2) {        $_SERVER['REQUEST_URI']='/'.substr($p, 0, strpos($p,'/',4)).'/'.substr($p, strrpos($p, '/')+1).'/'.($_SERVER['QUERY_STRING'] ? '?'.$_SERVER['QUERY_STRING'] : '');    }};fix_lang_subcategory();require_once('index.php');?>

After this, you should see WordPress's 404 file at /fix_lang_subcategory.php successfully. If it works, we can edit our .htaccess file.

At the end of your .htaccess file, after

# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]

lines, we add this line:

RewriteRule ^en/ /fix_lang_subcategory.php [L]

What we do here is that we change the entry point with our silly php file from wordpress's index.php to be able to run a few lines of php without touching original sources. This works only for /en/ part of the site. Rest works as it does now. In our php file, we check if we are seeing a link with subcategories and if there is, we alter (this is not a nice thing!) REQUEST_URI as below:

/en/maincategory/subcategory1/subcategory2/article/?anything_here_untouched

to

/en/maincategory/article/?anything_here_untouched

then we leave WordPress to do its job normally.

If the plugin works differently when you enable subcategories, then this can cause redirection of subcategoried pages under /en/.

A Better Solution:

I had thought you did not want to use subdomains for alternative languages; but then I saw "Can you host a version of the translated blog in a subdirectory/subdomain?" on comments to your question and in your reply, it looks like mention of subdirectory caused a misunderstanding. As I saw it on the ML plugin's website, you can use a subdomain instead of a folder which will save you from all the trouble, probably:

Instead of http://erik.landvall.se/en you may use http://en.erik.landvall.se/? Maybe?

An Even Better Solution:

90% of chance that ML Plugin causes this and they have to fix it. Starting a support ticket might help them realize their problem and fix it for everybody else.