.htaccess code
-
I've got a .htaccess file set up on a site to redirect specific old pages to specific new pages on a different site:
eg
Redirect 301 /oldpage.html https://www.newsite.co.uk/newpage.html
Redirect 301 /oldpage2.html https://www.newsite.co.uk/folder/
I have two questions:
1. Is that all the file needs? Or does it need any "rewrite engine on" type code?
2. I would also like to include code to "mop up" any other URLs and redirect them to the root, so that
/anyotherpage.html redirects to newsite.co.uk
Is there a way to do this?
-
What I'm looking to do is pass the link juice on from about 5,000 backlinks still pointing at our old site (which exists in domain form only a present) to the new site. Are these links pointed to the home page? Or are these pointed at relevant landing pages? If to the home page (and page is same on new site) nothing is needed. If these links are pointed to a landing page, you will need to route them to a related page on the new site and 301.
Are you saying there's not point in using a 301 if the page doesn't exist? Yes, no point unless there is a new landing page that is some-how related.
I don't really understand why you'd use a 301 if the page still existed...? If the page is on the new site and is the same url, no 301 is needed.
-
Thanks Kevin - I'm not sure I completely understand though.
What I'm looking to do is pass the link juice on from about 5,000 backlinks still pointing at our old site (which exists in domain form only a present) to the new site.
Are you saying there's not point in using a 301 if the page doesn't exist? I don't really understand why you'd use a 301 if the page still existed...?
-
Not really, since the resource doesn't exist anymore. If the resource exists (or something close to it) it would be a 301 and link juice will be passed (although not 100% of it).
If you have a relevant page, you should always 301 them. I would go through analytics and makes sure any "valuable" page has a relevant landing page. If no relevant landing page exists, you should 404 the result will eventually fall off.
I would also advise on creating a custom 404 page that explains what they are looking for and doesn't exist and show alternative pages/search bar. Users may get confused if they were looking for something specific and land at your home page.
-
Hi Kevin
Many thanks for this. Is a 404 as effective in passing on link juice as a 301?
-
2.) Are you talking about a catch-all? You can use 404 and redirect them to whatever. Try to redirect as much as possible though. Good luck!
ErrorDocument 404 /index.html
-
Thanks Andy, much appreciated. I'll look forward to the code
-
Your current redirects are fine and the best way is if its live to test it. Even thought I knew I had done it right recently when i went to https, I still do several random checks. They all came back as working - but no harm in testing.
Your point 2 is doable and as I am not on my laptop I don't have the code to hand. I will update in a few hours when back in the office for you, but your point 1 is correct.
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
-
Appending a code at the end of a URL
Hi All, Some real estate/ news companies have a code appended to the end of a URL https://www.realestate.com.au/property-house-qld-ormiston-141747584 https://www.brisbanetimes.com.au/national/queensland/childcare-centre-could-face-prosecution-for-leaving-child-on-hot-bus-20230320-p5ctqs.html Can I ask if there's any negative SEO implications for doing this? Cheers Dave
Technical SEO | | Redooo0 -
Redirect chain error free htaccess code for website
i want to redirect domain, example.com to https://www.example.com, is anyone can help me to provide redirect chain error free ht-access code. I implemented this htaccess code on the website and mhy site show on the moz redirect chain error RewriteCond %{HTTP_HOST} !=""
Technical SEO | | truehab
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(./)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]0 -
Proper 301 redirect code for http to https
I see lots of suggestions on the web for forwarding http to https. I've got several existing sites that want to take advantage of the SSL boost for SEO (however slight) and I don't want to lose SEO placements in the process. I can force all pages to be viewed through the SSL - that's no problem. But for SEO reasons, do I need to do a 301 redirect line of code for every page in the site to the new "https" version? Or is there a way to catch all with one line of code that Google, etc. will recognize & honor?
Technical SEO | | wcksmith10 -
If content is at the bottom of the page but the code is at the top, does Google know that the content is at the bottom?
I'm working on creating content for top category pages for an ecommerce site. I can put them under the left hand navigation bar, and that content would be near the top in the code. I can also put the content at the bottom center, where it would look nicer but be at the bottom of the code. What's the better approach? Thanks for reading!
Technical SEO | | DA20130 -
Should WordPress themes be hard coded for better SEO?
In the interests of making my site faster I have recently come across the suggestion of removing unwanted PHP from my WooThemes WordPress theme. The suggestion is to hard code the choices I have made in the WordPress template to reduce on database calls. Has anyone actually done this to their WordPress theme before and seen any measurable results?
Technical SEO | | Wallander1 -
Mod Rewrite / .htaccess avoid duplicate content
I have been searching and testing for hours but cannot find a solution. I am able to get a URL to display with out the file exntension. i.e domain.com/file instead of domain.com/file.php The problem is both versions of the URL above work, therefore a duplicate content issue. How can I force the URL with the file extension not to resolve and give a 404 error? Or just redirect to the non extension URL? IF it helps here is my code. Options +FollowSymLinks
Technical SEO | | MiamiWebCompany
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]0 -
Limits to 301 in htaccess?
I'm about to launch a redesign of my company's main website, and we've updated most of the URLs to be more user friendly and SEO optimized. I've just finished editing my spreadsheet, and see that I'll need to implement 244 redirects. My question is: Are there performance issues with loading your .htaccess file up with almost 250 301 redirect commands? I've heard a bloated htaccess file can really slow down apache, should I be approaching this a different way, maybe with php?
Technical SEO | | AdoptionHelp0 -
.htaccess problem using POST method
Hi guys I'm after some help with trying to achieve the following: 1. Canonicalise to http://www. 2. Remove the index.php from root and subfolders. I have the .htaccess code below, which seemed to work fine, but the urls use the POST method and this isn't working with the rewrites. Can anyone please advise as to what I am doing wrong? As you can probably guess .htaccess isn't my strongest SEO discipline! The code I have is: http:// to http://www. RewriteEngine on
Technical SEO | | TrevorJones
RewriteCond %{HTTP_HOST} ^mydomainexample.com
RewriteRule (.*) http://www.mydomainexample.com/$1 [R=301,L] /index.php to / Options +FollowSymLinks
DirectoryIndex index.php RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\ HTTP/
RewriteRule ^index.php$ http://www.mydomainexample.com/ [R=301,L] Subdirectory /index.php to / RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)index.(php|html|htm?)[#?]?
RewriteRule ^(([^/]+/))index.(php|html|htm?)$ http://www.mydomainexample.com/$1 [R=301,L] Just to add to this I have found this which I think is what I need to restrict it to GET: RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L] Thank you in advance for any suggestions as to how I may put this code together.. Trevor0