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
-
Incomplete Redirect for Domain Migration?
One year ago we migrated domain "X" to domain "Y". We did the proper redirects and used Google Search Console. Everything was done by the book. Now when we enter "Site: X" in Google about 650 results listing the old domain still come up. When clicked these redirect to the new domain. My SEO says that the old domain should not be indexed by Google, that these pages with the old domain should not appear. Is this in fact an incomplete domain migration? Our search traffic dropped considerably when we migrated the domain a year ago. My SEO thinks this may explain the drop. Thanks,
Intermediate & Advanced SEO | | Kingalan1
Alan0 -
How can i solve this redirect chain issue?
Hey, can somebody explain to me how can I solve this redirect chain issue? I tried redirecting /contact-us directly to **/contact/ **but this causes a chain of redirects of infinite dimensions. I don't know how to find the old redirect and delete it. Is there such an option? Thank you! byA7l
Intermediate & Advanced SEO | | Popos1 -
Should I redirect my HTTP to my HTTPS ?
I am about to make a domain name change for my online shop. I have heard that redirecting my HTTP to my https is a good SEO Practice. I have www, non-www, as well as https-www and https-non-www declared in Search console. Both have non-www set as preferred domain. Is the redirect rule from HTTP to https really usefull ? Thanks
Intermediate & Advanced SEO | | Kepass0 -
What happens to 301 redirect if the site taken down?
I understand 301 redirect carries over the page value to the page its being redirected to. However what happens if for example, I do a 301 redirect from example.com to example.co.uk, 2 months later I take down hosting and cancel domain for example.com, would I lose the page value that was being carried over to example.co.uk? Do I need to keep both domains active?
Intermediate & Advanced SEO | | Marvellous0 -
Should I redirect my xml sitemap?
Hi Mozzers, We have recently rebranded with a new company name, and of course this necessitated us to relaunch our entire website onto a new domain. I watched the Moz video on how they changed domain, copying what they did pretty much to the letter. (Thank you, Moz for sharing this with the community!) It has gone incredibly smoothly. I told all my bosses that we may see a 40% reduction in traffic / conversions in the short term. In the event (and its still very early days) we have in fact seen a 15% increase in traffic and our new website is converting better than before so an all-round success! I was just wondering if you thought I should redirect my XML sitemap as well? So far I haven't, but despite us doing the change of address thing in webmaster tools, I can see Google processed the old sitemap xml after we did the change of address etc. What do you think? I know we've been very lucky with the outcome of this rebrand but I don't want to rest on my laurels or get tripped up later down the line. Thanks everyone! Amelia
Intermediate & Advanced SEO | | CommT0 -
301 Redirect To Another 301 Redirect
Hi, We have a client with an old domain that they want to redirect to their primary domain. They also have a few older domains pointing to the old domain. Do you recommend leaving them as redirects that point to the old domain? This will create a redirect to a redirect situation. Or, is it better to go ahead and redirect those older domains to the primary one's, removing one layer of redirect? Thank you! Jessie
Intermediate & Advanced SEO | | JessieT0 -
Redirecting non-www pages to www ones
Hello:
Intermediate & Advanced SEO | | romanbond
I'm trying to consolidate all the link juice and see that some of my pages are linked to by using both www.mysite.com/whatever.html and mysite.com/whatever.html.
Is there a safe re-write rule that not just redirects non-www(s) to www(s), but designates the redirect as 301, so link juice will be transfered as well. If not RewriteRule, are there any other ways to accoplishe this? And the last question: can this be solved by simply setting Preffered domain in google webmaster tools to display www URL? Any help will be appreciated.0 -
Seeking Help with Domain Acquisition Redirect Strategy
My company is purchasing www.boughtsite.com. This new site has multiple sub-domain sites: customsite1.boughtsite.com, customsite2.boughtsite.com, etc. 1. Is it possible to redirect everything from www.boughtsite.com to www.mycompanysite.com while leaving the other sub-domain sites active? These other sites have different audiences than our main site. 2. Would it be an okay solution to just place a link on boughtsite.com to mycompanysite.com telling visitors "We have been re-branded to My Company" 3. Can I use an i-frame to move customsite1.boughtsite.com to www.mycompanysite.com/customsite1 instead? Thanks for your input!
Intermediate & Advanced SEO | | pbhatt0