Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

If I change a folder name in server ant thus the URL will be changed, could I perform 301 redirection or this is only for the case that the web page has been transferred to another folder?

share|improve this question
add comment

2 Answers

Entire folders can be redirected, just like files can. You can add a line like this to .htaccess:

Redirect permanent /OLD http://example.com/NEW

Which will cause every file in the directory to be 301 redirected:

  • http://example.com/OLD/page_one.html -> http://example.com/NEW/page_one.html
  • http://example.com/OLD/page_two.html -> http://example.com/NEW/page_two.html
  • http://example.com/OLD/an_image.png -> http://example.com/NEW/an_image.png

This is documented in Apache's mod_alias redirect documentation

share|improve this answer
    
So even in the case that it is for dynamic web pages (phpbb forum), according to you a single code line in the .htaccess folder is enough for such a redirection? –  hyweb Oct 9 '13 at 10:48
    
Yes, redirects are very simple to implement. –  Stephen Ostermiller Oct 9 '13 at 10:50
    
Please note that I have seen here: htaccessredirect.net/index.php and the code that arises for such a case is: //301 Redirect Entire Directory RedirectMatch 301 example.com/OLD(.*) example.com/NEW//$1 So it is not exactly as specified by you –  hyweb Oct 9 '13 at 11:01
    
RedirectMatch works as well, but it is not needed. RedirectMatch directives take more processing since they rely on regular expressions. Plain Redirect directives should be preferred when they work. The redirect documentation that I linked shows a very similar example with a folder redirected to a different subdomain and foo.txt being redirected inside it. –  Stephen Ostermiller Oct 9 '13 at 11:09
    
I have seen in the server that the .htaccess exists in www as well as in public_html... would it be the same either the one or the other to be changed? Moreover, could you please let me know where this code shall be added or it is not necessary to be added in specific place –  hyweb Oct 9 '13 at 11:16
show 2 more comments

If the URL has changed, you'll need a redirect. If a certain page was in site.com/folder1 before and is now in site.com.folder2, you'll need to redirect it. A 301 redirect is for the case that a page has been transferred to another folder, but for all practical purposes, changing the folders name is the same as putting the files in a different folder.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.