• Hi,

    I have a blog running which is installed as a sub directory, ie www.mydomain.com/blog – however the main website is now expanding to include localised version accessed via a sub directory, eg: www.mydomain.com/us, www.mydomain.com/eu etc…

    As such when a user is viewing one of these subdirectory website I need them to be able to view the blog posts via this sub-directory. Please note, the posts are NOT translated I just need the links to work, without changing the original links.

    For example I need:

    www.mydomain.com/blog/my-post

    to work but also for

    www.mydomain.com/us/blog/my-post

    to point to the same post and maybe so that I can pick up the ‘us’ part in my theme/templates.

    I have tried various rewrite rules in both the .htaccess in the root as well as the .htacccess in the sub-directory and whilst the links DO go to the blog, the return the WordPress 404 so the full request is not recognised

    • This topic was modified 5 years, 3 months ago by Jan Dembowski.
    • This topic was modified 5 years, 3 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Developing with WordPress topic

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    This .htaccess seems to work in root (or at least the equivalent for my site):

    RewriteEngine On
    RewriteBase /
    RewriteRule ^blog/ - [L]
    RewriteRule (.*)/blog/(.*) https://www.mydomain.com/blog/$2?reg=$1 [L]

    You have to do an external rewrite because of how WP uses the original request to figure out the requested permalink. Internal redirects don’t change this and the added /us/ or whatever confuses WP. This does mean the rewritten address shows up in the browser.

    You can see the inserted “/us/” regional parameter ends up appended as a “reg” query var which your page can get from $_GET.

    If you use a different URL structure like mydomain.com/blog/us/my-post/, you can use the WP Rewrite API to parse out the regional parameter and pass it as a query var.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding a variable prefix to wordpress urls’ is closed to new replies.