Title: Adding a variable prefix to wordpress urls
Last modified: August 8, 2019

---

# Adding a variable prefix to wordpress urls

 *  [drucifixion](https://wordpress.org/support/users/drucifixion/)
 * (@drucifixion)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/adding-a-variable-prefix-to-wordpress-urls/)
 * 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 6 years, 10 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
    -  This topic was modified 6 years, 10 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not a Developing with WordPress
      topic
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadding-a-variable-prefix-to-wordpress-urls%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/adding-a-variable-prefix-to-wordpress-urls/#post-11814282)
 * 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.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)
 * [Localization](https://wordpress.org/support/topic-tag/localization/)
 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [rewriterule](https://wordpress.org/support/topic-tag/rewriterule/)
 * [subdirectory](https://wordpress.org/support/topic-tag/subdirectory/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/adding-a-variable-prefix-to-wordpress-urls/#post-11814282)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
