Solved

htaccess code to 301 Wordpress subdomain to subfolder

Posted on 2014-09-03
3
154 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A step by step SEO guide to creating content that drives traffic and maximizes page views by using the right tricks, tools and keyword analysis. You are the subject matter expert.   You have forgotten more about your area of expertise than most …
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…

744 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

8 Experts available now in Live!

Get 1:1 Help Now