?
Solved

htaccess code to 301 Wordpress subdomain to subfolder

Posted on 2014-09-03
3
Medium Priority
?
199 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 2000 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
The purpose of this video is to demonstrate how to insert an Iframe into 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 : Open Page or Post…
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.
Suggested Courses

719 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