0
votes

i currently have wordpress blog with multiple subdomains. Currently the permalink structure is /%year%/%monthnum%/%day%/%postname%/ i want to change it remove year month and day and just put in postname. The problem if i do it now, the existing links will throw a 404 error, to avoid it i want to redirect current permalink structure to new permalink structure

for example i have url http://subdomain1.mydomain.com/2012/07/30/my-post-name/ then i want it to be redirected to http://subdomain1.mydomain.com/my-post-name/

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

the problem with the above regex is it redirects every subdomain to subdomain1.mydomain.com, i want to something like

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

the above thing is not working.

can you let me correct regex, i am ready to add a line .htaccess for each subdomain if required

1

1 Answers

0
votes

Solved it by removing the domain name

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ /$4

It solves my current requirement, but what if i wanted to some subdomains to redirect and some not to in the future. Can anyone provide a better solution.

tried the below one too but it did not work for me

RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteRule ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://subdomain.domain.com/$4 [R=301,L]