htaccess 301 redirect

This is kind of a general question, but I haven't found an answer yet:

I'going to move my WP blog and ZP installation to a new domain, and I'm at the point of adding a 301 redirect on my old domain.

I found this:

`
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]
`
which seems fine for an entire 'copy' of the old site. But I made some modifications:

/folderA/ becomes /folderB/ (the zenphoto installation)
/archives/ becomes /wp-content/uploads/ (all the links within wp-posts to images etc.)

and all the rest stays the same.

So I need three redirections, but I don't know how and in what order.

Comments

  • acrylian Administrator, Developer
    You need to add those afterward that. It is not exactly a redirection technically, its rewriting the url. It's the same server still, isn't it?

    For SEO reasons you should also take care of with and without www ("Duplicate content").

    `
    RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
    `
    This redirects calls to domain.com to www.domain.com so it is clear both have the same content.
  • Yes, the site will remain on the same server.

    So would this be ok?

    `Options +FollowSymLinks

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^spoenk\.nl$ [NC]

    RewriteRule ^(.*)$ http://www.jacktummers.nl/$1 [L,R=301]

    RewriteRule ^archives/(.*) http://www.jacktummers.nl/wp-content/uploads/$1 [R=301,L]

    RewriteRule ^beeldend/(.*) http://www.jacktummers.nl/collectie/$1 [R=301,L]`

    where
    www.spoenk.nl is the old domain, www.jacktummers.nl the new one.
    archives/ will be wp-content/uploads/
    beeldend/ will be collectie/ (this is the ZP installation)
  • acrylian Administrator, Developer
    Since you already rewrite the domain I think you don't need the full domain again.
    Actually just this is needed for the url change:
    `RewriteRule ^category/(.*)?/$ news/category/$1 [L,R=301]`
    That's an example from our own htaccess file to redirect the outdated Wordpress links.
    I am not an real htaccess expert though but that works for us.
  • Ok, just one more sample then, because it's so important. My old domain existed for ten years :), so I don't want to loose any links.

    `Options +FollowSymLinks

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^spoenk\.nl$ [NC]

    RewriteRule ^(.*)$ http://www.jacktummers.nl/$1 [L,R=301]

    RewriteRule ^archives/(.*) wp-content/uploads/$1 [R=301,L]

    RewriteRule ^beeldend/(.*) collectie/$1 [R=301,L]`
  • acrylian Administrator, Developer
    Different than the `(.*)?/$`we use at the end of the first url but best you try it anyway with all sorts of combinations before launching.
  • One more thing...
    If I would also want to add a redirect to a 404 page for visitors, would that line of code have to be BEFORE or AFTER these rewrite rules. And do I have to add RewriteEngine off somewhere?
  • acrylian Administrator, Developer
    I don't know right now but I guess that does not matter. Zenphoto uses its own 404 page.
    No, RewriteEngine OFF is not need as you want to keep it on, don't you?
  • Yeah, that makes sense :) I just thought that placing the errordocument before the rewrite code would make Google skip everything after that (the rewrite rules), thus not using those rewrites.

    `ErrorDocument 404 /404.html

    Options +FollowSymLinks

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^spoenk\.nl$ [NC]

    RewriteRule ^(.*)$ http://www.jacktummers.nl/$1 [L,R=301]

    RewriteRule ^archives/(.*)?/$ wp-content/uploads/$1 [R=301,L]

    RewriteRule ^beeldend/(.*)?/$ collectie/$1 [R=301,L]`
  • how can i redirect my website url to another
  • This is really not the right forum for your question as is is basic WEB stuff. Please see http://en.wikipedia.org/wiki/URL_redirection
Sign In or Register to comment.