How to Redirect
-
What is the htaccess code to redirect everything in a directory to a file?
Thanks!
-
I implemented this and it did not work. I did it exactly as you said and made sure rewrite engine is on.
Tyler
-
Hey Tyler,
The full code for the .htaccess file would be:
RewriteEngine on RewriteBase / RewriteRule ^domain.com/directory/(.*) http://domain.com/directory.html [R=301,L]
-
-
RewriteRule (.*) [http://www.newdomain.com/](http://www.newdomain.com/) [R=301,L]
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
-
Redirect Issue - Drop in ranking after CMS change
Hi Website - https://www.aasprint.com.au/ After we moved the site from wordpress to codeIgniter + angular there has been a huge drop in traffic and ranking. One of the thing we recently realized is the redirection - COULD THAT BE THE ISSUE? On the browser and sitemap the URL doesn't have "/" at the end When checked on redirection tool the URL seems to be redirecting to one with "/" at the end Attached are the screenshots. Also moz bar shows no redirection. However, the issue seems to be flagged by the site audit tool as 301 redirection. Not sure if it's the cause for the drop. What action to take? Any advice would be much appreciated. V7CNtqt j3dJ4TW
Intermediate & Advanced SEO | | Bhisshaun0 -
Java redirect harm page authority?
Hello! Our website using JAVA redirect (legal reasons) , I noticed that pages that have JS redirect don't get the same page authority for example:
Intermediate & Advanced SEO | | Roi.Bar
The old home page have 60 PA while the new home page get only 22 PA I know that Google don't have problem with JS redirects and they passing all the juice like regular 301
but all SEO tools are straggling to understand it, why? Does anyone know what I'm talking about?0 -
New Site (redesign) Launched Without 301 Redirects to New Pages - Too Late to Add Redirects?
We recently launched a redesign/redevelopment of a site but failed to put 301 redirects in place for the old URL's. It's been about 2 months. Is it too late to even bother worrying about it at this point? The site has seen a notable decrease in site traffic/visits, perhaps due to this issue. I assume that once the search engines get an error on a URL, it will remove it from displaying in search results after a period of time. I'm just not sure if they will try to re-crawl those old URLs at some point and if so, it may be worth it to have those 301 redirects in place. Thank you.
Intermediate & Advanced SEO | | BrandBuilder0 -
Redirecting site from html/php to wordpress
I've never come across this and haven't been able to really find anything that explains it very well. I want to get opinions before we make a definitive decision. Here's the scenario... I am working on a site that was built in HTML/PHP and some of the pages are ranking pretty well. (some page 1, but not number 1) We are going to start using the Wordpress platform by year's end. The pages that were built in html have been built a little spammy but they still rank. I just think they are keyword stuffed a little and not very "reader friendly" (I think the last person was spinning content). So, we've built completely new content on our new pages and we've commissioned really good content writers for them. I will be handling the on-page SEO going forward so I know what to do there. My questions are this.... Should I 301 the old pages to the new pages with the better content? (old pages have the .html or .php extensions so www.example.com/keyword.php will become www.example.com/keyword-keyword Is there any negative side to doing this since the content will be completely different then the old pages that are being 301 from. (Keywords are pretty much staying the same with the exception of minor variations. ie, www.example.com/red-cashmere-sweater.php to www.example.com/cashmere-sweater) I ask this because I've moved sites before where I've just changed the location of the same content. I've never done it where the content is changing and so is the URL extension. Thank you in advance for your help and guidance.
Intermediate & Advanced SEO | | DarinPirkey0 -
Redirecting a Page from Domain A to Domain B
We have a page on Domain A, an established and well-ranking website, that would be more appropriate on Domain B, a site that we launched about two years ago. This page ranks well, pulls nice search traffic and has traffic from external links. We would like to move the page and its traffic from Domain A to Domain B using a 301 redirect. Have you ever done this or have you heard of how it has worked for someone else? Thanks!
Intermediate & Advanced SEO | | EGOL0 -
Canonical or 301 redirect, that is the question?
So my site has duplicate content issues because of the index.html and the www and non www version of the site. What's the best way to deal with this without htaccess? Is it a 301 redirect or is it the canonical, or is it both?
Intermediate & Advanced SEO | | bronxpad0 -
Redirect
Hi, I have one domain which was redirected today (the main domain,root) was redirected to a new subdomain of the main root domain.site was ranking for several keywords and had an authority of 35 on root domain. Site after 12 hours disappeared from google results.dont even rank for its brand name. What will happened to the new subdomain? Will rank again? Have the same keywords plus some more.old keywords are 3 and new are 2. For the old keywords on page optimization gets a c , and for the new a+c. For the new keywords don't have backlinks at all. When my site will start to rank for its old keywords? How long will be down ? Will pass the link juice and authority? If yes how soon ? Because I will loose to much money if stay longer like 1-2 weeks down. Thanks
Intermediate & Advanced SEO | | nyanainc0 -
301 redirect every pages?
Good evening, my question might sound stupid but please forgive me, I am still learning SEO. If I build a new site that will replace an existing site. Is there any point to do a 301 redirect for pages that had no inbound link so, no juice to pass? I kind of think that it would be a better practice to 301 redirect each pages to a page that make sense on the new web site .... but here is why I think that. Why I say that If I am lucky, many of my old web site pages will be indexed, many of them having no inbound links. So once the new web site online, until all my new web sites pages are indexed, I could imagine Google would send people to the index pages (the old ones that do not exist anymore)... I am right? So in that case, if I do a 301 redirect only for pages that have inbound links, the user would end up on a 404 page. Could you tell me if it make sense how I think? Thanks a lot !! Nancy P.S. I would not redirect if it make no sense to the user. I fully understand that we must always keep the user experience in mind in any 404 and 301 redirect decisions. But to simplify the question, just suppose it is ok from a user perspective to map every old site pages to a page in new web site.
Intermediate & Advanced SEO | | EnigmaSolution0