Welcome to WebmasterWorld Guest from 3.80.6.254

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 permanent redirect

redirecting urls

     
8:50 pm on Jan 6, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 31, 2003
posts:172
votes: 0


Hi all,

I'm trying to do a permanent 301 redirect from one url to the other and because I'm using fp 2002 with fp extensions, my web host on apache says iI have to email them the script for them to put into the .htaccess file. I would prefer to do it myself, but i suppose I have no other choice?

Anyway, I'm not entirely sure of the correct code, I am fairly sure that the code below wouldn't be correct, but it would be handy as a starting point.

What do I need to change please?

Do I need to specify the url that its coming from?

Any help appreciated.

RewriteEngine ON
RewriteCond %{HTTP_REFERER} ^http://www.mysite.com/gallery.html.*$ [NC]
RewriteRule ^.*_001.jpg$ http://www.mysite.com/redirect.html [R,L]

[edited by: jdMorgan at 2:35 am (utc) on Jan. 8, 2004]
[edit reason] de-linked [/edit]

4:16 am on Jan 7, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


dougie,

There are three problems:

  • You have specified a 302 redirect. Use [R=301,L] instead.
  • You'll need to add a RewriteCond to prevent the redirected URL from being redirected in turn, causing an "endless loop."
  • You can't redirect from an image to an html page, as intended by your code - the browsers don't do this. You can get away with redirecting from a jpeg to a gif or vice-versa, but even that's not a great idea.

    The RewriteCond to prevent looping for your specific substitution - as given above - would be

     RewriteCond {REQUEST_URI} !/redirect\.html$ 

    However, that third problem is a killer, so I can't provide anything useful until that is resolved.

    Jim

  • 8:22 am on Jan 7, 2004 (gmt 0)

    Junior Member

    10+ Year Member

    joined:Dec 31, 2003
    posts:172
    votes: 0


    Many thanks Jim, best to start from scratch. Does anyone have the complete code for a permanent 301 redirect please.
    4:38 pm on Jan 7, 2004 (gmt 0)

    Senior Member

    WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

    joined:Mar 31, 2002
    posts:25430
    votes: 0


    dougie,

    Here are some resources:

    Introduction to mod_rewrite [webmasterworld.com]
    Apache mod_rewrite documentation [httpd.apache.org]
    Apache URL Rewriting Guide [httpd.apache.org]
    Using Regular Expressions [etext.lib.virginia.edu]
    Topic Search on WebmasterWorld [google.com]

    Jim

    8:32 pm on Jan 7, 2004 (gmt 0)

    Junior Member

    10+ Year Member

    joined:Dec 31, 2003
    posts:172
    votes: 0


    Many thanks Jim,

    I did actually look at the info you suggested, but to my non-tech brain, it seems a bit tricky to grasp.

    There's 3 domain names, forexample1.com, forexample2.com and forexample3.com, but only 1 website.

    forexample1.com has a good pr and forexample3.com is the one that I would like anyone to be riderected to, from ANY pages in either forexample1.com or either forexample2.com

    Do I need to specify anywhere, any of the details of the domain names that are being redirected FROM?

    I have to send the code to my web host for them to do. They use Apache and mod_rewrite.

    Here's the sample code:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^forexample.com$
    RewriteRule ^(.+) http://www.forexample.com/$1 [L,R=301]

    Can anyone please let me know if this is correct please?

    Dougie.

    [edited by: jdMorgan at 2:35 am (utc) on Jan. 8, 2004]
    [edit reason] de-linked [/edit]

    12:24 am on Jan 8, 2004 (gmt 0)

    Senior Member

    WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

    joined:Mar 31, 2002
    posts:25430
    votes: 0


    dougie,

    Redirect forexample1.com and forexample2.com to forexample3.com:


    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^forexample1\.com [OR]
    RewriteCond %{HTTP_HOST} ^forexample2\.com
    RewriteRule ^(.*)$ http://www.forexample3.com/$1 [L,R=301]

    Jim
    8:20 am on Jan 8, 2004 (gmt 0)

    Junior Member

    10+ Year Member

    joined:Dec 31, 2003
    posts:172
    votes: 0


    Jim,

    Many, many thanks for this Jim.

    One thing, after stacks of hours searching these archives, I seem to remember one the threads that you were involved in, saying that spaces are a bit of a prob on this board?

    is the code above *exactly* how it should be, ie are the spaces ok, bearing in mind the prob with the spaces here?

    Also, is there a limit to how many domain names you can redirect FROM, could you put 10 for example?

    Your help is very much appreciated.

    Dougie.