: Combine redirect to naked domain and point existing content to /blog I think the .htaccess setup for this ought to be fairly straightforward, but I'm having a hard time with it for some reason.
I think the .htaccess setup for this ought to be fairly straightforward, but I'm having a hard time with it for some reason. I've just completed the migration of a WordPress single site installation to a MultiSite setup, and everything went swimmingly. Now, though, I need to redirect all the original blog posts to /blog/<post> (because WordPress enforces that on MultiSite).
I also recently migrated everything to the naked domain. This in and of itself wasn't a problem – until I added in the /blog/ component.
Here is what I have for the naked domain redirect (which, as noted, works fine):
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ %1/ [R=301,L]
I've tried a number of things for the /blog/ redirect, but it's continuing to throw me. It seems like it should be fairly easy with RedirectMatch:
RedirectMatch 301 ^/(.*/?)$ <my-site>/blog/
The problem, of course, is that this expression then captures /blog/ and promptly heads off to /blog/blog/blog/...
I run into the same problem using another RewriteCond/RewriteRule pair, and when I tried to work around it like this:
RewriteCond %{HTTP_HOST} ^(?:(www.))?(.*)$ [NC]
RewriteRule ^(?<!(blog/))(.*)$ %1/blog/ [R=301,L]
The result was a redirect loop (I'm not seeing what's causing it, but my head is obviously not processing the regexes correctly this morning).
It seems to me like RedirectMatch is the way to go anyway; I just need to make sure not to capture /blog/ itself.
Edit: I totally forgot about the ! part of the rule; should I simply be starting that RewriteMatch with !^blog?
More posts by @Yeniel560
1 Comments
Sorted by latest first Latest Oldest Best
You could just do this:
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(/?)(.*) /blog/ [L,R=301]
then anything that doesnt have a /blog in it will be rewritten to have the /blog in it.
(referenced from stackoverflow.com/questions/4844069/htaccess-rewritebase)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.