DoktaDivah
DoktaDivah

Reputation: 1

htaccess redirect for WordPress posts but NOT pages to subdomain

I'm organizing a client site into several subdomains. I've used the following to redirect all the posts on oldsite.com/blog-post-name to blog.oldsite.com/blog-post-name and it works like a charm. However, we want oldsite.com, oldsite.com/page1 and oldsite.com/page2 to remain as they are and NOT be redirected to the subdomain. I feel like I should be able to add an exception for the applicable pages - there are only 5 of them - but I can't figure out how that exception should read. For reference, oldsite.com is in the root directory and WordPress files are in oldsite/subdomain/subfolder.

oldsite.com htaccess:

RewriteEngine on
RewriteBase / 

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ http://blog.oldsite.com/$1 [R=301,L]

Update

Old code started breaking the theme CSS, and incidentally so does the new code. I'm thinking the negative condition is fighting with the basic WP htaccess. Here's what I have at the moment:

RewriteEngine on
RewriteBase / 

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^(repairs|contact)/?$
RewriteRule ^(.*)$ http://blog.oldsite.com/$1 [R=301,L]

# 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]
</IfModule>
# END WordPress

Should I be adding the conditions within the WP set? Why did the code above work before (yes, with WP code)?

Upvotes: 0

Views: 253

Answers (1)

anubhava
anubhava

Reputation: 785196

You can do:

RewriteEngine on

RewriteCond %{REQUEST_URI} !^/(page1|page2)?$
RewriteRule ^(.*)$ http://blog.oldsite.com/$1 [R=301,L]

Upvotes: 0

Related Questions