lets say i renamed a folder. does anyone know how i can write a 301 redirect in .htaccess to redirect every file in that folder to the new folder? thanks
Go read this article http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm But if you are using cpanel use the 301 tool
This works to redirect an entire domain to the same page on a new domain: Redirect 301 / http://www.internet-search-engines-faq.com/ Therefore, it seems to me that this should work to redirect a single directory: Redirect 301 /marketing http://www.internet-search-engines-faq.com/promotion More details are at How do I create a 301 Redirect?
That article states: This is factually incorrect, which leads me to believe that the author never tested his suggestions.
Here is the Apache documentation on mod_rewrite, which should help considerably in understanding how to do redirects properly. (It helps a lot if you are familiar with "regular expressions"--if you are not, Google up some tutorial on that before getting into the mod_rewrite docs.)
True; what you can often get by knowing about is mod_alias, the Apache documentation for which is at http://httpd.apache.org/docs/mod/mod_alias.html, where they note that A more powerful and flexible set of directives for manipulating URLs is contained in the mod_rewrite module. It's simply the classic power-vs-simplicity tradeoff thing. The mod_alias Redirect directive can adequately handle many straightforward redirects; its RedirectMatch can handle slightly more complex arrangements; but mod_rewrite is the heavy artillery, for when complex redirects are needed. (And "complex" needn't actually be terribly complex). It's as well to know at least something about mod_rewrite--if nothing else, to know when you might be able to best use it--and once you do, it tends to become habit to use it in all redirects.
I am unclear on something concerning this topic. I have some pages I used to promote my site (when I first started since I did not know what I was doing) and have since removed the pages and would like to implement a 301 redirect (I think). Currently, I am just using a ErrorDocument 404 http://www.quadaenterprises.com/locallinks.htm type of redirect. Well, that of course shows up as a temporary redirect which as I understand it tells the spiders that the pages that are no longer on my site are only gone temporarily. I would like to direct any requests for these "gone" pages to my home page. There are too many pages to list individually and they were all in their own folder so I was hoping I could just do this redirect 301 /doors http://www.quadaenterprises.com. I have tried this and it does not seem to work. Is there an easy way to make this work? Should the .htaccess be in the doors folder with that in it (it is currently in the root of the domain)? Thank you, Brent
I'm not sure I have the details correct, so if I have them wrong do please post the correct info. But, as I understand it, you want to redirect any call for a page that was in http://www.quadaenterprises.com/doors/ to the index page of that same site. You want the .htaccess file to be in your root. There are occasions for putting ancillary .htaccess files in subdirectories, but those are usually rather specialized needs. You should be able to get by with something like this: <IfModule mod_rewrite.c>RewriteEngine On RewriteBase / RewriteRule ^doors/(.*) http://www.quadaenterprises.com/ [R=301,L]</IfModule> If you try using the simpler mod_alias directive-- Redirect 301 /doors http://www.quadaenterprises.com/ --what I believe would happen is that a call for http://www.quadaenterprises.com/doors/foo.html would be redirected to a call for http://www.quadaenterprises.com/foo.html, which I gather is not what you are looking for.
Trying to clarify a little bit. I have several pages listed, at Google for instance (http://www.google.com/search?num=100&hl=en&lr=&ie=UTF-8&q=site%3Awww.quadaenterprises.com), that are www.quadaenterprises.com/doors/foo.htm. I would like to have any call for any file in the doors (also an extras) folder to go to www.quadaenterprises.com/used-for-sale.htm. My goal is to indicate to the spiders that these pages no longer exist and hopefully the search engines will unindex the pages. Meanwhile, I do not want to lose the traffic these "pages" are creating. So, I would use something like this in my .htaccess file (which is in the root directory of the site): <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^doors/(.*) ^extras/(.*) http://www.quadaenterprises.com/used-for-sale.htm [R=301,L] </IfModule>
Thank you for your help. I have got things working the way I think I want them to. I will see what the search engines do with it over the next week or so.
A rookie here on 301 redirect ".htaccess" however wondering how hard it is to have a http://www.forums.domain.com to be http://forums.domain.com. Can anyone provide 301 re-direct .htaccess code or sample where I just change directory and domain names in a file with a bit of instructions? Thanks a bunch.
I just moved the contents of one directory (first letter uppercase) to another (all lower case) including subfolders etc like so: RewriteRule ^News/?(.*) http://www.coffeesh0p.com/news/$1 [R=301,L] RewriteRule ^Shop/?(.*) http://www.coffeesh0p.com/shop/$1 [R=301,L] RewriteRule ^IRC/?(.*) http://www.coffeesh0p.com/irc/$1 [R=301,L] RewriteRule ^Info/?(.*) http://www.coffeesh0p.com/info/$1 And so on. The $1 on the end of the URL appends anything extra after /dirname/ onto the new dir. EG /Shop/6/SA001/ would redirect to /shop/6/SA001/ on the new domain. Hope that helps.
That was SO helpful. Thank you. I had a temporary blog installation that got indexed by Google and I didn't want to lose those indexed pages, so I used this to refer them from /blog3 to /blog2 on the server. Big help. Thanks!
Thanks for sharing your valuable info Synchronium. Do you think its possible to tweak your code to move an entire site to another domain or subdomain ( keeping the same structure of cource) ? maybe something like this ? RewriteRule ^/?(.*) http://www.newsite.se/$1 [R=301,L] /Vlad