Redirect language permanently - .htaccess

I need to delete Spanish language on a website and redirect all pages to the English version of the site. Preferrably redirect each page to the associated page in the English version (Pages are associated in the Joomla Menu).
mydomain.com/es/quienes needs to go ot mydomain.com/about
or
mydomain.com/es and mydomain.com/es/quienes need to go to: mydomain.com
Now I know I could redirect them one by one using Redirect 301 rules but is there an easier way using RewriteCond and RewriteRule
Thanks

Related

.htaccess 301 redirect just for Google bots

I want to redirect my old domain to a new one but not for users - just for Google bots.
I have manager this code but i am not sure of it. Could you help?
RewriteCond %{HTTP_HOST} oldsite\.pl$ [NC]
RewriteCond %{HTTP_USER_AGENT} Googlebot
RewriteRule ^ http://newsite.pl [L,R=301]```
What you are implementing is against Google's webmaster guidelines and will get your site penalized such that it doesn't appear in the Google search results at all.
Serving different things to users and Googlebot is called cloaking. Serving redirect to Google and content to users is a form of cloaking called sneaky redirects. To quote Google:
.. some redirects deceive search engines or display content to human users that is different than that made available to crawlers. It's a violation of Google Webmaster Guidelines to redirect a user to a different page with the intent to display content other than what was made available to the search engine crawler. When a redirect is implemented in this way, a search engine might index the original page rather than follow the redirect, while users are taken to the redirect target.
So you shouldn't be doing this if you want to have your site still indexed by Google.
One alternative would be to use canonical tags that point to your new site. Canonical tags are invisible to users but tell search engines to prefer to index one particular copy the site.

Redirect all traffic if referrer is external

My old website is located in public_html. I have a new version of the site, which i installed in public_html/new/ .
I want to redirect all traffic from https://example.com to https:/example.com/new but i want to allow users to browse the old version (https://example.com) if they click a link from my new site.
Tried using:
RewriteCond %{HTTP_REFERER} !^https://example.com/.*
to match the referrer, but it doesn't seem to work.
Any help would be much appreciated.
RewriteEngine On RewriteCond %{HTTP_REFERER} !^https://example.com/.*
​RewriteRule ^$ https://example.com/new/? [R=301,L]
You've implemented this as a 301 (permanent) redirect (as it would need to be for SEO if you are migrating from an old to new site). However, the 301 redirect will be cached persistently by the browser. And redirect the user back to /new (from cache) without making a request to the server.
(This redirect also only redirects the old homepage. Inner pages are not redirected. Is that the intention?)
This would need to be a 302 (temporary) redirect - to avoid the redirect being cached, but that's not so good for SEO.
You could include a ?noredirect=1 parameter on URLs back to the old site (in the root) - a different URL - and only redirect when this param is not present. However, you would need to persist this URL param across all URLs having navigated from the new to old site. (And would allow anyone to access the old site by simply appending this URL param.)
However, #CBroe's suggestion in comments would be preferable. To move the old site to an /old subdirectory and the new site replaces the old site in the root. This would be better for SEO and users. Optionally, you could then simply block access to /old if the Referer is not the same domain (which would allow links from the new to old). And would prevent (most) bots from accessing /old (although you would still implement a X-Robots-Tag: noindex HTTP response header). Note, however, the Referer is unreliable and might not be set at all by some browsers (user's settings).

Redirect in htaccess from one path to another

I would like to change our site structure a little bit and decided to have the product overview not in http://www.example.com/en/ but in http://www.example.com/en/products/
I did not manage it to redirect it from /en/ to /en/products/ (or /en to /en/products/).
The page is not online so far (Testmode) and I don't have to care about 301 Pages for Google at the Moment.
Can anybody help?

Old pages PR to

I have site that has many links to its pages. And I will completely renew site, update CMS, content and page structure. Domain remains the same.
What will get users in browser if they find somewhere on the Internet old link
to old sites page and follow by that link while it's already a new site and
old page where link leads to doesn't exist?
How to make a redirect or something from these old links if old
pages not open to root of domain?
What's about Google in that case how do not lost PR and
redirect that PR weight of old pages to main domain?
I am kindly appreciate any relative discussion on this topic because it's really interesting from all sides.
What will get users in browser if they find somewhere on the Internet old link to old sites page and follow by that link while it's already a new site and old page where link leads to doesn't exist?
They will get a 404 Not Found.
How to make a redirect or something from these old links if old pages not open to root of domain?
You'll need to create a 301 redirect from every old page to the equivalent new page. You can do it using mod_alias:
RedirectMatch 301 ^/old_page/(.*)$ /new_page/$1
or mod_rewrite:
RewriteRule ^old_page/(.*)$ /new_page/$1 [L,R=301]
You'll obviously need to tailor the matching expressions and targets to your specific needs. If you have a lot of individual URL's that need redirecting, you may want to look into creating a RewriteMap.
What's about Google in that case how do not lost PR and redirect that PR weight of old pages to main domain?
As long as you use 301 redirects (a permanent redirect, as opposed to 302, a temporary redirect) Google's page ranking will transfer to the new URL.
What's better to use mod_alias or mod_rewrite in this situation and why?
Either is fine, but mod_rewrite gives you a lot more options and allows for rewrite maps. But if you are doing something simple, mod_alias is fine.
Again the same with 301 and 302 what's better to use here?
You want 301 here. It means "the resource that you requested has permanently moved to HERE" as opposed to a 302 which means "the resource that you requested isn't here right now, but in the mean time, you can find it HERE". Also, Google won't transfer any page ranking to the new page if you only do a 302 redirect, since it's meant only for temporary redirects. Not when a page has permanently moved to a new URL.
And the last I just looked on the old pages they all like domain.tld/index.php?id=77 does this rule correct RewriteRule ^index.php?id=(*)$ / [L,R=301] in that case for any id number to root?
This rule will not work. You cannot match against the query string (the ?id= part) in a RewriteRule, only against the %{QUERY_STRING} var in aRewriteCond. Also(*)` is probably not what you want.
This will 301 redirect any request for /index.php?id=N where N is any number, to the document root.
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^index.php$ / [L,R=301]

Mass 301 redirect

HI -
I have a site (built years ago) which uses .htm extension on most pages.
I'd like to switch to a Wordpress CMS and use the "html on pages" plugin to re-create the whole site, but then, of course, I would end up with html extensions on all my pages and lose all my search engine placement for the original .htm pages, many of which have first page placement in the SERPs.
What is the correct syntax for a mass 301 redirect that tells the bots that all pages which formerly used .htm extensions are now .html?
Thanks in advance for any help!
J.
What web server are you using?
On Apache you might say:
RedirectMatch permanent ^(.*)\.htm$ /$1.html
(Aside: it's not just SEO! By keeping your old links alive and redirecting to the new ones, you keep incoming traffic and avoid annoying users with 404s.)

Resources