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
-
How do I find why I have a 302 redirect?
I have a 10 year old website and I have just recently changed to a https: version and my host ionos setup a 301 redirect. I have noticed on my Moz reports that as well as a 301 redirect there is also a 302. How do I find why I have a 302 redirect? I have looked in my htaccess file and it says:- RewriteCond %{SERVER_PORT} 80
Web Design | | Ast9858
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L] I'm assuming this is the 301 redirect, where will I find the 302 redirect. Please note that I am using Wordpress that was not setup through ionos. Does anyone know where a 302 redirect could also be installed or how I find why its there or where its coming from? Thanks Andrew0 -
Any risks involved when we have huge list of redirects in our website database?
Hi all, We have changed hundreds and thousands of page and page URLs for last 10 years in our website. So, now we are going to redirect most of the old pages/links to the current related pages. This will increase the number of redirects we set in our website database to thousands. Will this put any extra weight on crawler and any risks involved for employing too many redirects. Thanks
Web Design | | vtmoz0 -
Why use a wwwP subdomain naming convention
While working through a series of crawl reports and competitive insights for a site, I noticed one of the competitors had switched from a WWW-version to a wwwP-version. Looking back at the snapshot I took of this during the same time period in 2014, I noticed a significant drop in PA/DA by 20+/-. I'm curious to know if anybody else has experienced something similar, and if anybody can provide insights on why a change like this would even be made? I'll preface it with, everything we could see that this competitor was doing from the outside, was legitimate and propelling them in a positive direction.
Web Design | | dodgejd0 -
Wordpress - redirecting tags
I just ran a webmaster tool from Yoast SEO premium and notice I have a lot of problems with tags (restricted-robots-txt) For example : http://www.soobumimphotography.com/tag/wedding-group-photo/ Do I have to redirect to http://www.soobumimphotography.com/wedding-group-photo/ Should I do this to each and every posts Thank you
Web Design | | soobumim0 -
Is it necessary to Remove 301 redirects from Wordpress after removing the 404 url from Google Webmaster?
There were many 404 urls in my site found by Google Webmaster. I've redirected these urls to the relevant urls with 301 redirect in wordpress. After that I removed these 404 urls from Google Index through Webmaster. "Should I cleanup these 301 redirects from Wordpress or not? ". Help Needed.
Web Design | | SangeetaC0 -
Best way to indicate multiple Lang/Locales for a site in the sitemap
So here is a question that may be obvious but wondering if there is some nuance here that I may be missing. Question: Consider an ecommerce site that has multiple sites around the world but are all variations of the same thing just in different languages. Now lets say some of these exist on just a normal .com page while others exist on different ccTLD's. When you build out the XML Sitemap for these sites, especially the ones on the other ccTLD's, we want to ensure that using <loc>http://www.example.co.uk/en_GB/"</loc> <xhtml:link<br>rel="alternate"
Web Design | | DRSearchEngOpt
hreflang="en-AU"
href="http://www.example.com.AU/en_AU/"
/>
<xhtml:link<br>rel="alternate"
hreflang="en-NZ"
href="http://www.example.co.NZ/en_NZ/"
/> Would be the correct way of doing this. I know I have to change this for each different ccTLD but it just looks weird when you start putting about 10-15 different language locale variations as alternate links. I guess I am just looking for a bit of re-affirmation I am doing this right.</xhtml:link<br></xhtml:link<br> Thanks!0 -
Question About Site Redesign and Nav / Page Structure
Hey guys, i am currently redesigning our company's site, and have come across some things that I'm not quite sure of. We used to have individual service pages in our main navigation (design, video, marketing) before the redesign. In this new design, i had the idea of making just one "services" or "capabilities" page, where these three services would each be outlined, and each service would have a list of links to more specific landing pages. Obviously, breaking it up correctly with HTML5 using the andtags. What I'm wondering is that if i'm going to be penalized for having those three services that aren't necessarily related too closely on the same page as opposed to having the one page for each service (like we have now). Any help would be greatly appreciated, and let me know if i need to elaborate more. Thanks in advance!
Web Design | | RenderPerfect0 -
Given the lastest Google update, should I rewrite my Flash site or try to present an alternative HTML/CSS site?
I have a site that was created using Flash. The reasoning behind this was, at the time, that I didn't care if the site ranked or not (portfolio site). Now I would like to drive traffic to the site from SE's. Given the Penguin update, should I rewrite my Flash site in HTML/CSS or present an alternative site for bots and browsers that don't support Flash? My concern is that by presenting an alternative site to bots and non Flash supporting browsers that the SE's will see potentially see this as cloaking. Thoughts and advice would be much appreciated.
Web Design | | mj7750