I have a site where mydomain.com and mydomain.com/frontpage serves the exact same content.
Socalled SEO experts tell me it is very bad to have the same content on different addresses. Google will cast upon me a terrible fate.
So I thought fine, I'll just redirect mydomain.com to mydomain.com/frontpage, but I'm failing miserably. I just can't wrap my head around htaccess commands.
I need to have visitors who visits mydomain.com or www.mydomain.com to be redirected to www.mydomain.com/frontpage in a way to that it becomes visible in the browser address field.
BUT nothing else must be redirected.
For example, www.mydomain.com/anotherpage must still be there.
My .htaccess is already full of a lot of rewrite rules that redirects all of these user-friendly addresses to the real urls (index.php?pageid=341) etc. So I'm thinking I would first redirect mydomain.com to mydomain.com/frontpage and then let another RewriteRule later make sure that mydomain.com/frontpage actually points to index.php?pageid=341.
But mydomain.com => mydomain.com/frontpage must be a visible redirect, while all the other rewrite rules are hidden from the user.
How does the Redirect or RedirectMatch or RewriteRule look like, that redirects visitors from www.mydomain.com to www.mydomain.com/frontpage while keeping other addresses like e.g. www.mydomain.com/anotherpage ?
Thanks.
You can insert this new rule just below RewriteEngine On line:
RewriteRule ^/?$ /frontpage [L,R=301]
Related
I am using RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^.+$ http://newsite.com%{REQUEST_URI} [L,R=301] to redirect users from one site to another. The root exception in this instance is deliberate; that is, I want visitors to oldsite.com to not be redirected, but visitors to oldsite.com/anypage to be redirected to newsite.com/anypage.
However, when someone manually types in oldsite.com/qwerty (a non-existing page), they (and presumably any search engine) get a 301 redirect and not a 404 error. Is there a rule-based way to avoid this behaviour or do I need to change my .htaccess so that there are individual 301 redirects listed (so that anything else will then give the desired 404 result)?
For simplicity I will refer to "Google" here, but it applies to any search engine.
This is basically a non-issue. The 301 redirects are mostly there to keep your Google ranking from the old domain on the new domain and keep bookmarks valid. If a page existed on the old domain, it should still exist on the new domain.
If someone types a non-existing page on the old domain, the user will see the 404 message on the new domain, but that is okay. Google does not crawl that url. In fact any automated crawler should never encounter that url, so semantics about getting a 301 redirect before a 404 status code does not really apply.
There are two things to look out for:
You had a page on the old domain that now exists under a different name on the new domain. You should add a manual exception for this:
RewriteRule ^mypage$ https://newsite.com/new-page-with-something-fancy [R=301,L]
You had a page on the old domain that no longer exists on the new domain. You should manually add an exception that returns the "Gone" status code
RewriteRule ^i-no-longer-exist$ - [G,L]
There does not really exist a way of checking the status code of the redirected page, unless you go into the land of rewriting to a script that uses something like curl to check the other site, or use something like a proxy. Both are awfully inefficient and hurt your site's ranking more than it could ever gain.
So I have found some questions that are close to what I need, but I haven't found exactly what I'm looking for.
While I've worked with htaccess files in the past, it's pretty much been just copying and pasting code that is proven to work, or just doing simple 301 redirects. To be honest, I get pretty confused when looking at htaccess rewrite rules, so unfortunately are not going to be able to do from scratch. So I'm really hoping there is someone kind enough to provide a code example just using placeholder domain names.
Here is my situation. I'm doing work for a company who has split up into different divisions (4). So they want to take the site on their current domain, move it to a different domain. Then put up a simple html splash page on the old domain that provides links to the 4 different sites they will have (one of those being what was the old site on a new domain).
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage. Not sure if this matters, but site that was on the old domain was a WordPress site so technically is index.php. But the new site/splash page is named index.html.
Thanks in advance!
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage.
You can use this rule in the site root .htaccess of olddomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(css|js|images)/ [NC]
RewriteRule . http://newdomain.com%{REQUEST_URI} [L,NE,R=301]
RewriteRule . will match everything except the home page just make sure this rule is the first rule in your .htaccess.
Just wondering if its possible to 301 redirect an existing Rewriterule?
For example if I have the following line in my .htaccess file :
RewriteRule ^blue-widgets/ bluewidgets.php
and then I need to change my URL structure but the url "blue-widgets/" has a good ranking in the search engines which I dont wont to lose, is it possible to add another rewrite rule (301) that redirects that url too "newdirectory/blue-widgets/" ? If so, how is this done, is it a simple case of adding the new rewriterule under the existing one?
Does the fact that you have 2 rewrites, slow the page down or have any other problems?
You are confusing two quite different aspects: internal and external rewrites.
301 and 302 are external rewrites and in effect pass the redirect instruction back to the user's browser to do. 301 tells the browser (and the search engines) that the address change is permanent.
Rewrite rules without the [R] flag do an internal redirect -- that is a remapping inside the Apache / IIS subsystem than is not exposed to the outside world.
Yes, you can have multiple URI internally redirecting to the same target, but as you've written them, they will not be external and not 301s.
Try
RewriteRule ^blue-widgets/$ /new-directory/blue-widgets/ [L,NC,R=301]
RewriteRule ^new-directory/blue-widgets/$ bluewidgets.php [L,NC]
Does the fact that you have 2 rewrites, slow the page down or have any other problems?
The 301 to send blue-widgets to new-directory/blue-widgets is cached and will only happen once per client, so the performance should be minimally affected.
However, if you can, you should also change this link on your site to be new-directory/blue-widgets
I´m trying to do a 301 redirect in a htacess file. I want to point all pages on one domain to one single page on another domain and I do not want to manually redirect all single pages.
Ex: www.olddomain.com/1.html and www.olddomain.com/2.html should both point to www.newdomain.com.
Hope anyone could help me.
RewriteCond %{HTTP_HOST} .*olddomain\.com$
RewriteRule ^ http://www.newdomain.com/one-single-page.html [L,R=301]
I had the same problem but this works fine for me to accomplish what you want, i actually need to opposite, for each page from old domain to redirect to new domain but keep inner structure so ill keep looking i guess!
redirectMatch 301 ^/ http://www.newdomain.com
I have a domain www.siteA.com, which uses Joomla, while the domain www.siteB.com is empty.
I would like to show the content of the domain www.siteA.com at www.siteB.com.
I tried to solve the problem first by making a domain redirection by .htaccess, but I could not show SiteA's content at SiteB.
How can you show the contents of mysiteA.com at mysiteB.com by domain masking in .htaccess?
You really should be doing this by CNAME-ing the domain, but if you really want to use .htaccess you can do what #Unkwntech suggests
Edit: It would just look like
www.siteB.com CNAME www.siteA.com
Whichever way you do it (CNAME or htaccess) you're probably going to get an SEO penalty for duplicate content.
RewriteEngine On
RewriteRule ^.*$ http://www.siteA.tld/$1 [NC]
This should rewrite every request to siteA.