Solved

htaccess code to 301 Wordpress subdomain to subfolder

Posted on 2014-09-03
3
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 18

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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

636 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