2

QUICK UPDATE

Ok getting there Is this mod_alias?

RedirectMatch 301 ^/ http://brightmist.co.uk/

I've added this one line of code underneath everything and it appears to work, however my other directories such as http://brightmist.co.uk/blog/2013/02/23/manchester-art-gallery-feb-2013 are telling google these pages have temporarily moved - see http://www.internetofficer.com/seo-tool/redirect-check/

Does this mean I have to go right the way though my site and add a tone of redirects?


ORIGINAL QUESTION

I have a new website. I'd like to redirect all of my old site links from http://artygirl.co.uk to my new one http://brightmist.co.uk/

I'm primarily a designer with years of experience using mainly in Photoshop, CSS, HTML, Wordpress, and jQuery but I don't know much about editing things like the htaccess file. And I don't want to get it wrong as it means google ranking drops etc

Does anyone know of any script I can paste into the bottom of my htaccess file, I'd like it to redirect all links/pages on the site to the same place as before. For example if I type http://artygirl.co.uk/buy-art-prints-cheshire/ I want it to go to http://brightmist.co.uk/buy-art-prints-cheshire/ I'm using the same host, they've just re-pointed the domain

Among other things my host has recently added the following code, I assume this is also to do with the domain mapping, also here is my whole htaccess file -

ErrorDocument 401 /forms/401.html
ErrorDocument 403 /forms/403.html

RewriteEngine On
RewriteBase /

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 218.143.4.127
deny from 143.90.221.204
deny from 95.135.78.190
deny from 114.108.150.74
deny from 95.135.111.205
deny from 91.124.239.150
deny from 94.178.2.93
deny from 91.124.206.118
deny from 91.124.226.116
deny from 118.98.32.34
deny from 94.180.252.133
deny from 58.27.140.58
deny from 77.93.197.83
deny from 88.191.63.27

# Hotlink Protection START #

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?brightmist.co.uk [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

# Hotlink Protection END #
Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
brightmist.co.uk
  • 531
  • 5
  • 18
  • 47
  • Why don't you just try with a redirect in the .hataccess file in `http://artygirl.co.uk`. Something like this: `Redirect 301 / http://brightmist.co.uk/` I can't see the reason to use `mod_rewrite`, at least not from your question, `mod_alias` is much faster and easy to use. – Felipe Alameda A Mar 04 '13 at 18:06
  • Thanks for your comment faa. Please can you explain further. the site is located at the same host/place I guess this is why it loops? Please can you post the full code. I'm a designer so don't really know anything about the htaccess coding. – brightmist.co.uk Mar 04 '13 at 18:12
  • It is another domain, though. What I suggest is to use just one line in the .htaccess file in the root directory of the old site. Like this:`Redirect 301 / http://brightmist.co.uk/`, That's ll you need to redirect everything to `http://brightmist.co.uk/`, including URL-paths and queries. Of course, in the new site the old directory structure and files have to exist. – Felipe Alameda A Mar 04 '13 at 18:16
  • Nope sorry the host has been renamed to brightmist.co.uk and artygirl.co.uk has been mapped/redirected to this new host brightmist.co.uk. I've got the 301 working properly (see below answer) but it doesn't redirect all the links? Is there a sting of htaccess code I can add to this? – brightmist.co.uk Mar 04 '13 at 18:30
  • That's exactly what I am saying. Try using `mod_alias` (In my comment) instead of `mod_rewrite` (In your answer). It is much faster. And yes, Google will catch up with a permanent redirect (301). – Felipe Alameda A Mar 04 '13 at 18:47
  • Thanks again faa. Please can you post the full code. I am not a developer so don't know how to write mod_alias? I'm clueless to the difference! – brightmist.co.uk Mar 04 '13 at 18:55

3 Answers3

5

I'd like to redirect all of my old site links from http://artygirl.co.uk/ to my new one http://brightmist.co.uk/

There are several ways to achieve that, all of them should be implemented in one .htaccess file in http://artygirl.co.uk/ root directory.

There is no need to check for the incoming domain as it must be artygirl.co.uk, where the .htaccess file is located.

To use any of the following options, copy-paste the corresponding directive or rule-set into one empty .htaccess file in http://artygirl.co.uk root directory.


The fastest one is a simple Redirect using one mod_alias directive:

Redirect 301 /  http://brightmist.co.uk/

Any path in the incoming URL will be appended automatically to the redirected URL.


To redirect only certain paths using another mod_alias directive:

RedirectMatch 301 ^/(.*)  http://brightmist.co.uk/$1

Although this example redirects everything, the regex ^/(.*) can be modified to match only certain URL-path pattern.


To redirect only certain paths using mod_rewrite directives:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)   http://brightmist.co.uk/$1  [R=301,NC,QSA,L]

As in the previous option, although this rule-set redirects everything, the regex ^(.*) can be modified to match only certain URL-path pattern.


NOTES

  • The same directory structure and files in http://artygirl.co.uk/ must exist in http://brightmist.co.uk/ for any of the previous options to work.

  • If the actual .htaccess file in your question works as expected, you could use it in http://brightmist.co.uk/ root directory where the new WP is installed. Might require some modifications, though.

  • To move or copy a WP install, check this link Changing the site URL.


UPDATE:

From these sentences in your comment to this answer: "My domains both point at the same directory..." and "...now it creates a loop...", maybe the question is about domains pointing to the same content (Website), normally known as parked domains.

If that's the case, I am not sure redirecting in .htaccess the primary domain to the parked one is the correct approach just to change the domain name in the browser's address bar.

However, in theory something like this should do it using mod_rewrite directives:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST}  artygirl\.co\.uk      [NC]
RewriteRule ^(.*)   http://brightmist.co.uk/$1  [R=301,NC,QSA,L]

Redirects permanently any request from http://artygirl.co.uk to http://brightmist.co.uk, appending the complete incoming path and query when present.

Since the .htaccess file is also shared, I think this rule-set should be placed at the top of the .htaccess file in the question, replacing the following lines:

RewriteEngine On
RewriteBase /
Community
  • 1
  • 1
Felipe Alameda A
  • 11,791
  • 3
  • 29
  • 37
  • Wow Thanks Faa, I'm confused. My domains both point at the same directory. This worked last night - RedirectMatch 301 ^/ http://brightmist.co.uk/, but now it creates a loop, although bizarrely my first blog post seems to redirect correctly. And the code in my site has reverted back to mod_rewrite. I guess there isn't a way to make sure the links all redirect as 301 so I'll have to do them individually as mod_rewrite. Thanks For your help I'll try this tomorrow – brightmist.co.uk Mar 07 '13 at 22:12
  • Yippee. Thanks Faa You're a Genius! Mod rewrite worked like a dream. And all my pages now appear as 301 permanent to google. Thanks so much! – brightmist.co.uk Mar 09 '13 at 15:43
0

Are they redirecting to the same extension? Should be something like this:

RewriteEngine on 
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Matthew Camp
  • 866
  • 5
  • 9
  • Ah do you mean the cms system. Its wordpress – brightmist.co.uk Mar 01 '13 at 22:17
  • The files are all the same host. They've just renamed it and pointed my new domain name. Then I changed the database and wpconfig file to recognise my new domain Brightmist – brightmist.co.uk Mar 02 '13 at 18:12
  • Did you try adding what I put(replacing the domain) in your htaccess file? – Matthew Camp Mar 04 '13 at 19:07
  • Thanks Matthew, Yes it sent back an error. The Developer in the comments above says I should use mod_alias, but I have no idea how to right this! I've managed to get the 301 working with some different code, as in my answer below. Would you happen to know how I can redirect all my links automatically with one string of code, without causing a loop. Both domains point to the same host. Say if I type http://artygirl.co.uk/blog/2013/02/23/manchester-art-gallery-feb-2013/ I want it to redirect to http://brightmist.co.uk/blog/2013/02/23/manchester-art-gallery-feb-2013/ – brightmist.co.uk Mar 04 '13 at 19:21
  • Here is another stack question which appeared not to find an answer http://stackoverflow.com/questions/10643271/how-to-301-redirect-all-pages-to-the-same-pages-on-new-domain – brightmist.co.uk Mar 04 '13 at 19:39
  • As per your answer below: (RewriteCond %{HTTP_HOST} !^brightmist\.co\.uk$ [NC] RewriteRule ^(.*)$ http://brightmist.co.uk/$1 [R=301,L]), should be working fine. The old urls just need to be crawled by Google than updated. – Matthew Camp Mar 05 '13 at 16:29
0

I see the problem. It redirects the root fine but if I go to:

http://artygirl.co.uk/photography/

I think you want it to go to

http://brightmist.co.uk/photography/

and not

http://brightmist.co.uk/

as it does currently.

Rewrite rules are notoriously hard to debug, but try this...

RewriteEngine On
RewriteBase  /
RewriteCond %{HTTP_HOST} !^brightmist\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://brightmist.co.uk/$1 [R=301,L]

I know this is really similar to what Matthew Camp answered. The RewriteCond is very important to avoid endless loops because you are delivering both domains from the same folder. You only want to redirect the one that's incorrect.

Rewrite Base might also be required depending on how the servers are configured and what other rewrite rules exist at higher levels (invisible to you but which might still affect you). Try with and without the RewriteBase.

I hope this helps.

Octopus
  • 8,075
  • 5
  • 46
  • 66
  • Thanks very much Octopus, but that's what I've already got and it still doesn't work! – brightmist.co.uk Mar 09 '13 at 15:37
  • @Judi The RedirectMatch that you have is overriding the rewrite rules and directing everything to the root. I believe you would be better off removing that and just getting the rewrite rules right. – Octopus Mar 09 '13 at 20:36
  • Thanks Octopus are you talking about faa's answer. This is what I used in the end and it worked perfectly! Options +FollowSymlinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) http://brightmist.co.uk/$1 [R=301,NC,QSA,L] – brightmist.co.uk Mar 10 '13 at 20:47