Solved

htaccess code to 301 Wordpress subdomain to subfolder

Posted on 2014-09-03
3
166 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 17

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

740 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