Ignoring url prefix using wordpress permalinks

I’m trying to set up an htaccess rule that’ll work with the current permalink structure i have.

The current permalink structure I have is this

Read More
/%category%/%postname%/

And my htaccess is as follows

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

And a typical url would be

/blog/post_category_name/post_name/

Which all works well and good. The problem I’m facing is that a user is able to change their locale which in turn prefixes the url with the region cod as below.

/uk/blog/post_category_name/post_name/

The problem now is that WP takes blog as the category and post_category_name as the post name which then throws a 404 within WP.

Essentially I want to completely ignore the region code, is this possible?

I should also add, that the uk (or any other region) directory doesn’t exist,

Thanks

Related posts

Leave a Reply

1 comment

  1. If you want to catch the uk/ folder, you have to do that at the root directory. Put this in the root .htaccess (you can check for !-f and !-d if you want to make sure it’s not already a dir/file).. this will allow you to grap the country code from the query string.

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteRule ^([a-zA-Z]{2})/blog/(.*) /blog/$2?ccode=$1 [L,QSA]
    </IfModule>
    

    You can ignore the country code also:

    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /
     RewriteRule ^([a-zA-Z]{2})/blog/(.*) /blog/$2 [L]
    </IfModule>
    

    Not sure if that will change something in WP (not sure how they process the url). You’ll have to check.