Solved

htaccess code to 301 Wordpress subdomain to subfolder

Posted on 2014-09-03
3
157 Views
Last Modified: 2015-01-06
Hi there,

Please could you help me write a piece of code for the .htaccess file of a wordpress site?

We've managed to get the site mirrored from a subdomian to a subfolder for SEO purposes.  I now need to update the htaccess code so that ALL PAGES of the blog are 301'd across to the relevant subfolder pages as in the example below:

Current Structure
homepage: http://blog.domain.com
post example: http://blog.domain.com/post-titles/
page example: http://blog.domain.com/page-titles/

New Structure:
homepage: http://www.domain.com/blog/
post example: http://wwwdomain.com/blog/post-titles/
page example: http://wwwdomain.com/blog/page-titles/

However, the only way to access the Wordpress CMS is still through the sub domain, therefore the path http://blog.domain.com/wp-admin/ would need to be excluded from the redirect.

Here is the only other code in the file:

# 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>

Please help. Thank you.
0
Comment
Question by:ChilliSauce
3 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40301777
In the htaccess in the subdomain folder use

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

Open in new window

0
 
LVL 16

Accepted Solution

by:
Lucas Bishop earned 500 total points
ID: 40317659
Update the .htaccess in the blog.domain.com with the following code (this includes the WP code already installed):

# 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]
RewriteCond %{HTTP_HOST} blog.domain.com [NC]
RewriteCond %{REQUEST_URI} !^/wp-admin/$
RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [R=301,L]
</IfModule>

Open in new window


This will provide a 'parallel redirect' which allows the old files and folders, to point to the new files and folders, rather than just redirecting everything to the new root folder and losing potential link juice, while also excluding the wp-admin folder from the redirect process.
0
 
LVL 8

Expert Comment

by:Sam Cohen
ID: 40333996
Why don't you just change the wordpress site structure?
You can add a plugin called search and replace https://wordpress.org/plugins/search-and-replace/

Check mark all tables
search for: blog.domain.com
replace with: domain.com/blog

Now you would be able to use domain.com/blog/wp-admin to login!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now