View Full Version : 301 redirect for an entire directory
al2six
Jul 16th 2004, 12:18 am
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
Foxy
Jul 16th 2004, 12:33 am
Go read this article
http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm
But if you are using cpanel use the 301 tool
Will.Spencer
Jul 16th 2004, 1:19 am
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? (http://www.internet-search-engines-faq.com/301-redirect.shtml)
Will.Spencer
Jul 16th 2004, 2:12 am
Go read this article
http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm
That article states:
The 301 directive is quite powerful. You can redirect not just single files but entire sites, e.g.
redirect 301 / http://www.you.com/
The first "/" indicates that everything from the top level of the site down should be redirected.
Note: using the above is not a good strategy in relation to search engine rankings as all current links within the search engine results will redirect to the top level of the new location.
This is factually incorrect, which leads me to believe that the author never tested his suggestions. :eek:
Owlcroft
Jul 17th 2004, 4:05 pm
Here is the Apache documentation on mod_rewrite (http://httpd.apache.org/docs/mod/mod_rewrite.html), 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.)
Will.Spencer
Jul 17th 2004, 8:58 pm
Of course, you don't need to learn about mod_rewrite to do a 301 redirect in .htaccess. :)
Owlcroft
Jul 18th 2004, 7:02 pm
Of course, you don't need to learn about mod_rewrite to do a 301 redirect in .htaccess.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.
batkerson
Jul 21st 2004, 6:10 am
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
Owlcroft
Jul 21st 2004, 8:23 pm
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)?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.
batkerson
Jul 22nd 2004, 5:13 am
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>
batkerson
Jul 23rd 2004, 6:27 am
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.
ColinR
Jul 28th 2004, 3:01 pm
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.
Synchronium
Aug 3rd 2007, 5:32 am
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.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.