Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
301 Redirect in htaccess for existing Wordpress site.
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- 301 Redirect in htaccess for existing Wordpress si...
301 Redirect in htaccess for existing Wordpress site.
04-05-2011 4:11 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I'm having trouble getting my head around the general expressions I need to add to my htaccess file for use with Wordpress now that I'm using it with jtonline.info newly hosted by Plusnet.
I have an existing Wordpress site in a directory called 'blog' off the root of ccgi. Since I pointed my domain to the root of the ccgi server I have moved the Wordpress index.php and .htaccess files to the root, amended the Wordpress site & url fields via the dashboard settings and performed an update of my Permalinks as per the Wordpress instructions about having Wordpress in its own directory.
Wordpress is working correctly using the new domain name, however, I would like to have all instances of the old address that are around permanently redirected to the new url structure. So, for example -
http://ccgi.jtonline.plus.com/blog/site-map/
I should like redirected to -
http://www.jtonline.info/site-map/
Note that the 'ccgi.username.plus.com' bit is replaced with 'www.jtonline.info/' and the '/blog' bit has been removed, then whatever happens to be in the url after '/blog' is added back on.
I should be grateful if someone could just post the code I need to add to the .htaccess file so that I can get this sorted, and then I'll try and learn for myself how it's done in due course.
My current .htaccess is as follows:
Many thanks.
I have an existing Wordpress site in a directory called 'blog' off the root of ccgi. Since I pointed my domain to the root of the ccgi server I have moved the Wordpress index.php and .htaccess files to the root, amended the Wordpress site & url fields via the dashboard settings and performed an update of my Permalinks as per the Wordpress instructions about having Wordpress in its own directory.
Wordpress is working correctly using the new domain name, however, I would like to have all instances of the old address that are around permanently redirected to the new url structure. So, for example -
http://ccgi.jtonline.plus.com/blog/site-map/
I should like redirected to -
http://www.jtonline.info/site-map/
Note that the 'ccgi.username.plus.com' bit is replaced with 'www.jtonline.info/' and the '/blog' bit has been removed, then whatever happens to be in the url after '/blog' is added back on.
I should be grateful if someone could just post the code I need to add to the .htaccess file so that I can get this sorted, and then I'll try and learn for myself how it's done in due course.
My current .htaccess is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
Many thanks.
Message 1 of 5
(9,680 Views)
4 REPLIES 4
Re: 301 Redirect in htaccess for existing Wordpress site.
05-05-2011 1:11 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I think what you need (at the top of that .htaccess file) is
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ccgi\.jtonline\.plus\.com$ [NC]
RewriteRule ^blog/(.*) http://www.jtonline.info/$1 ; [R,L]
David
Message 2 of 5
(409 Views)
Re: 301 Redirect in htaccess for existing Wordpress site.
06-05-2011 12:47 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks so much spraxyt, that did the trick nicely. It looks like I was being overly complex with the expressions I was trying to use and wasn't getting anywhere, hence the cry for help.
As I understand it, the first line you've used sets a condition to look for http:// and then anything that matches the old url in upper or lowercase.
The second line then starts at the blog/ part of the url and stores all that follows it in $1 and then finally redirects to the new url with the contents of $1 appended. The R means it's a redirect and the L says it's the last rule for the condition.
Since I've done a bit of testing and it all appears to be working, I've changed the [R,L] to [R=301,L] so that search engines know that it's a permanent redirect.
The redirect broke the display of images in my posts because the media upload url gets hardcoded into the post content, but I fixed that by using phpmyadmin to do a search and replace on the database.
Thanks again for your help.
Jules.
As I understand it, the first line you've used sets a condition to look for http:// and then anything that matches the old url in upper or lowercase.
The second line then starts at the blog/ part of the url and stores all that follows it in $1 and then finally redirects to the new url with the contents of $1 appended. The R means it's a redirect and the L says it's the last rule for the condition.
Since I've done a bit of testing and it all appears to be working, I've changed the [R,L] to [R=301,L] so that search engines know that it's a permanent redirect.
The redirect broke the display of images in my posts because the media upload url gets hardcoded into the post content, but I fixed that by using phpmyadmin to do a search and replace on the database.
Thanks again for your help.
Jules.
Message 3 of 5
(409 Views)
Re: 301 Redirect in htaccess for existing Wordpress site.
06-05-2011 3:56 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Pleased to hear that worked, and making it R=301 is correct for a permanent redirect. 
The way rewrite rules work is only partly top to bottom. So what happens here is that in server-context the URI is stripped of the scheme (HTTP) and hostname (www.jtonline.info OR ccgi.jtonline.plus.com) parts and mapped to the (same) physical file system path. In per-directory context (.htaccess) the physical path part up to and including the / before the current directory is then stripped and matched against RewriteRule patterns starting from the top of the .htaccess file.
Hence http://www.jtonline.info/blog/anything OR http://ccgi.jtonline.plus.com/blog/anything will match the ^blog/(.*) pattern so the rule is processed (with $1 set to the string anything). It goes back to RewriteConditions associated with that RewriteRule now, working through these top to bottom (if more than one).
Our first RewriteCondition tests if the hostname is ccgi.jtonline.plus.com (the backslashes escape the full stops to make them real ones and not meta characters that match any character). As you said the NC flag is given so the comparison is not case sensitive. The www. form fails that so further processing of the rule stops and the next rule is examined. The ccgi. form matches, and since there are no more conditions substitution on the RewriteRule takes place as you described. The flag R=301 causes the substitution to be processed as a permanent redirect, and L makes this the last rule processed. After the redirect processing starts again, but this time with the www. form of hostname and without /blog; so this rule is skipped.
I think the reason images weren't located is because they aren't where this rule would redirect the search. Changing the database patched that problem from posts, but a direct request (eg from a search engine link) will still fail. I think another rule is needed to cover this - to be covered later …
David

The way rewrite rules work is only partly top to bottom. So what happens here is that in server-context the URI is stripped of the scheme (HTTP) and hostname (www.jtonline.info OR ccgi.jtonline.plus.com) parts and mapped to the (same) physical file system path. In per-directory context (.htaccess) the physical path part up to and including the / before the current directory is then stripped and matched against RewriteRule patterns starting from the top of the .htaccess file.
Hence http://www.jtonline.info/blog/anything OR http://ccgi.jtonline.plus.com/blog/anything will match the ^blog/(.*) pattern so the rule is processed (with $1 set to the string anything). It goes back to RewriteConditions associated with that RewriteRule now, working through these top to bottom (if more than one).
Our first RewriteCondition tests if the hostname is ccgi.jtonline.plus.com (the backslashes escape the full stops to make them real ones and not meta characters that match any character). As you said the NC flag is given so the comparison is not case sensitive. The www. form fails that so further processing of the rule stops and the next rule is examined. The ccgi. form matches, and since there are no more conditions substitution on the RewriteRule takes place as you described. The flag R=301 causes the substitution to be processed as a permanent redirect, and L makes this the last rule processed. After the redirect processing starts again, but this time with the www. form of hostname and without /blog; so this rule is skipped.
I think the reason images weren't located is because they aren't where this rule would redirect the search. Changing the database patched that problem from posts, but a direct request (eg from a search engine link) will still fail. I think another rule is needed to cover this - to be covered later …
David
David
Message 4 of 5
(409 Views)
Re: 301 Redirect in htaccess for existing Wordpress site.
06-05-2011 9:19 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Quote from: spraxyt ... I think the reason images weren't located is because they aren't where this rule would redirect the search. Changing the database patched that problem from posts, but a direct request (eg from a search engine link) will still fail. I think another rule is needed to cover this - to be covered later …...
The images uploaded for display in the posts require the /blog directory to be in the URI and the full URI is hardcoded into the post (not relative). It was a quick process to use phpmyadmin to search the post content table in the database and replace all instances of the ccgi bit with the new domain name.
None of the images inside the posts should be viewed by a direct request, only the post URI, so patching the database is OK.
Message 5 of 5
(409 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- 301 Redirect in htaccess for existing Wordpress si...