How to rewrite/redirect a folder name with .htaccess
-
I have a folder in my site that I want to rename. I don’t want to just rewrite the URL and keep my old folder name, I want to change the folder name and then do whatever is necessary with .hataccess to not lose search engine rankings. The folder name I want to change has a space in it and also is misspelled (whoops x2)
Example.
Mysite.com/old foldr/page.html
Mysite.com/newfolder/page.html
How would I go about doing this with .htaccess? Do I just switch the folder name on my server and then set up a redirect, or do I do a rewrite? Sorry now familiar with the terms or .htacces.
Thanks all
-
You might possibly have to detail the white-space explicitly with \s
RewriteEngine On
RewriteRule ^old\sfoldr/(.*) /newfolder/$1 [R=301,NC,L] -
Yes, Bradley's method will allow you to redirect everything in the folder. I thought you were just needing to re-index one file.
-
Ok thank you! Unfortunately there are LOTS of .html files within this folder, is there a way to just switch the folder name and not each individual file?
-
To 301 redirect all files in the direct to the new directory in .htaccess, try this:
RewriteEngine On
RewriteRule ^old\ foldr/(.*) /newfolder/$1 [R=301,NC,L]This should redirect all HTML pages, images, you name it. It should also account for the space too.
You'll want to move all your files to the new folder location so when the redirect happens your end user doesn't receive a 404 error.
-
Yes, you will want to create a 301 redirect from the older location to the newer location.
Steps to take:
1. Change the folder on your server from /old foldr/ --> /newfolder/
2. Add this line in your .htaccess file:
redirect 301 /old%20foldr/page.html http://www.mysite.com/newfolder/page.html
**3. Make sure this is working properly. ** I like to use this 301 redirect checker tool:
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Disallow: /sr/ and Disallow: /si/ - robots.txt
Hello Mozzers - I have come across the two directives above in a robots.txt file of a website - the web dev isn't sure what they meant although he implemented robots.txt - I think just legacy stuff that nobody has analysed for years - I vaguely recall sr means search request but can't remember. If any of you know what these directives do, then please let me know.
Web Design | | McTaggart0 -
Needs clarification: How "Disallow: /" works?
Hi all, I need clarification on this. I have noticed we have given "Disallow: /" in one of our sub-directory beside homepage. So, how it going to work now? Will this "Disallow: /" at sub-directory level going to disallow only that directory or entire website? If it is going to work for entire website; we have already given one more Disallow: / at homepage level blocking few folders. How it is going to handle with two Disallow: / commands? Thanks
Web Design | | vtmoz0 -
302 redirects, canonicalise or redirect (301)?
Hey Guys, I am fairly new to 'technical' SEO as I was lucky enough in my old role to have technical expertise in the team for things like this, now I am learning myself and it is a slow and painful process, so your expertise is soooo much appreciated! My I.T. dept say that I have 3 instances on my website where the Hybris platform is creating a 302 redirect automatically - the first: URL doesn't exist - Hybris creates a temp 302 - the system does not create case sensitive url's | http://www.example.fr/Example/Marques/0180/brand/CHANEL | URL doesn't exist | TRUE | 302 | | http://www.example.fr/Example/Marques/0015/brand/Giorgio-Armani | URL doesn't exist | TRUE | 302 |
Web Design | | eLab_London
| http://www.example.fr/fr/Example/marken/0507/brand/lancome | URL doesn't exist | TRUE | 302 | I believe these are being redirected due to the fact that capital letters are being created in the url. Multi-lingual redirects I have a German and French version of my site and whenever any switches from one URL to the other using our language selector a 302 is created. Dynamic URL elements Dynamic url elements and special characters are being created in the URL, I am not sure where this is happening, but my I.T. department would like me to go and see whether this is something that can be created by a browser. If anyone has any similar problems or have any advice or insights even, I would love to hear from you! Thanks 🙂0 -
What should I know about redirecting users based on cookies?
Hi Moz! My client wants to redirect users to a basic or professional version of their site based on cookies. What do we need to do/know to make sure implementation is SEO-friendly? What if a user has cookies turned off? Are there any other obstacles? Thanks for reading!
Web Design | | DA20130 -
How to redirect special pages to new domain?
Hello. I have 2 websites in diffrent category and i want to move some of my visitor that arrived in specific page of doamin1 (url like this: http://example.com/pages/.........)to root of domain 2.
Web Design | | vahidafshari450 -
Duplicate home page /index.asp /index.php etc
We recently moved www.devoted2vntage.co.uk to shopify but seem to have multiple home page variants still in google index. I am concerned that these will be causing duplicate content. I have redirected the offending URLs below to www.devoted2vintage.co.uk/ and have set up a canonical URL but need an expect to tell me if I have taken the current steps and if not, exactly what I need to do. www.devoted2vintage.co.uk/index.php www.devoted2vintage.co.uk/index.htm www.devoted2vintage.co.uk/index.html www.devoted2vintage.co.uk/index.shtml www.devoted2vintage.co.uk/index.aspx www.devoted2vintage.co.uk/index.cfm www.devoted2vintage.co.uk/index.pl www.devoted2vintage.co.uk/index.asp
Web Design | | devoted2vintage0 -
Does anyone think the <figcaption>attribute from HTML5 will have any influence for image search?</figcaption>
There is a <figure>element that is supposed to provide better descriptions of image on the web in HTML5 - do you think that will replace the importance of the "Alt" tag? Link to figcaption description </figure>
Web Design | | RankSurge2 -
XML Sitemap that updates daily/weekly?
Hi, I have a sitemap on my site, that updates but it isn't a XML sitemap. See here: http://www.designerboutique-online.com/sitemap/ I have used some free software to crawl the site and create a sitemap of pages, however I think that if I were to upload the sitemap, it would be out of date as soon as I listed new products on the site, so would need to rerun it. Does anyone know how I can get this to refresh daily or weekly? Or any software that can do it? I have a web firm that are willing to do one, but our relationship is at an all time low and I don't want to hand over £200 for them to do one. Anyone with any ideas or advice? Thanks Will
Web Design | | WillBlackburn0