I have a site and a subdomain, so for example let's say:


In my hosting the subdomain store is actually a folder on the root site.

ON the main site, I want to do a permalink rewrite to remove the dates from the permalink, but NOT on the store.mysite subdomain. I used Yoast's redirect tool to get the htaccess code, which is:

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://www.example.com/$4

This works on the root, but it also applies this to the subdomain. I tried using this htaccess rule only work on the root site:

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^([0-9]{4})\/([0-9]{2})\/([0-9]{2})\/(.*) \/$4 [R=301,NC,L]

But now the redirect doesn't even work at all. I've searched everything I can find but cannot find a specific use case like this. Any experts on htaccess care to give me a hand and let me know what's wrong with my code? Thanks!

  • 1
    Could you elaborate why are you doing this with htaccess over configuring the site to have desired structure?
    – Rarst
    Jul 11, 2016 at 18:07
  • When the site was originally setup, the permalink was setup to use the year/month/day format for both the main site and the store. However, later on it was decided that the main site needed to lose the dates from the permalinks, but to keep the dates on the store. In order to do that, we changed the permalinks on the main site and added the normal RedirectMatch in htaccess. However, since the store site is a subdomain (a folder within the main site) the rules apply there as well and the posts on store get redirected to the main site. Jul 12, 2016 at 18:54

1 Answer 1


I figured out my own answer, so am posting it here so if someone else runs into the same problem, they can see what I did.

The issue for me was that the base Wordpress redirect code:

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

# END WordPress

was at the top of the htaccess file, so it was firing first before any of the redirects were. When I moved that to the bottom, the redirects began working again.

So if you are going to use the rewritecond and rewriterule, they need to go BEFORE the Wordpress rewritecond and rewriterule.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .