htaccess 301 redirect - how to disable it? - apache

I have added 301 redirect on my website by mistake (because I was doing maintenance). Now lots of people can't get back to my website, because they are still redirected to other page - eventhough I removed redirection (even deleted htaccess). As much as I searched around it's because htaccess (or 301 redirect) is cached in users browser and I wasn't able to find any solution for this. Is there any way to fix this, I can't just loose hundreds of visitors because of something like this?

This page explains what is going on in good detail:
301 Redirects: The Horror That Cannot Be Uncached
Basically, modern browsers cache the redirect response for 301 for some indeterminate amount of time and will not make an updated request to your old web page to refresh it. Users can manually clear the cache and, because it is a cache, data can be purged if the browser needs more space for other data (like other redirects).
This SuperUser question resolves the caching issue from the client's end:
How can I make Chrome stop caching redirects?
One interesting answer is:
//superuser.com/a/660522/178910
In this answer, the user points out that the browser treats http://example.com/ and http://example.com/? as two different URLs. You could go to the "new" site and setup an HTTP 302 redirect pointing back to the original page with a ? on the end and it should load. If they original page already had a query as part of the URL, you can simple add an & to the end to achieve the same result.
It's not perfect -- it is a different URL after all -- but at least they'll be able to view your old site.
Note that your web application may try to redirect empty queries or invalid queries back to a "clean" page, which you may have to disable to get the intended result.
UPDATE
One other option is to put a redirect from the new site back to the old site (make this a 302 or 307 redirect to avoid the 301 problem you're currently having). From my testing, Chrome will remove the old redirect when it does this. It may throw a "redirect loop" error, but only once. I was unable to reproduce the cached redirect problem at all with the latest version of Firefox. Other browsers' behavior is probably going to be inconsistent.

Related

ERR_SSL_PROTOCOL_ERROR on a domain forwarding to another [duplicate]

I inherited a domain that previously had a 301 redirect from the root ("/") to "/index.shtml"
I've removed the redirect and a different site on the domain, but people who visited the site in the past will have the redirect behavior cached in their browsers... for a terribly long time, unless they manually clear their caches.
Anyone trying to go to example.com in these browsers will be sent to example.com/index.shtml before they even make any HTTP requests. Right now this is a huge problem because there is no index.shtml, but is there something I can do with headers to tell browsers to "forget about that redirect you just did!"?
The short answer: There is no way to tell the browsers of the users to "forget" the R 301 redirect. 301 means permanent, it can be only undone on action of the user or when the cache expires.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2
Similar Q and A on Stackoverflow:
Apache - how to disable browser caching while debugging htaccess,
Cannot remove 301 redirect
Try to avoid 301 redirects and use 302 (temporarily) instead. Here is an article how to set no cache for 301 redirects (didn't try it):
https://github.com/markkolich/blog/blob/master/content/entries/set-cache-control-and-expires-headers-on-a-redirect-with-mod-rewrite.md
What you could do in your scenario: You could add a header redirect to the file index.shtml, which sends the user to the original file, where he should usually go.
This can be done by a clear data-only cache.
It can remove all,.htaccess redirects changes from the browser.

301 or 404 redirect?

One of my websites is constantly being scanned for WordPress directories and files. This particular site never had or will have WordPress. If it did then I would follow the standard practices outlined at Hackertarget to prevent getting hacked.
There currently is a blank 404 page for the site (not really user friendly, but that's the point). This does not seem like the best option so I am considering using either an internal 301 redirect or possibly redirecting any requests for /wp/*, /wordpress/*, etc..., over to WordPress.org.
A similar question was asked, but I am not concerned about SEO and those answers do not address this particular scenario.
So, which is best?
1. Keep the blank 404.
2. Internal 301.
3. External 301.
The 404 response is certainly the standard. Any of the 300 codes will just divert the traffic to another site, which would be rude on your part. If you are being scanned, don't expect the scanner to take heed of the "permanence" of your 301 response. Please, go with the 404.

SEO - 301 redirect via 404 page

I am new to this so I will try to explain myself clearly.
I am doing my 301 redirect from a custom 404 page. Now I got it working my question is more regarding how google would treat this. Cause we going to a 404 page would google just record it as a 40 page or would it actually record the 301? As i said I am new to this and have looked through google to try and find an answer to this.
Anyway any help or comment would be greatly appriciated. thanks in advance
Best practice in this case could be:
If the page doesn't exist, but we have new one, with highly similar content, we can make 301 redirection, simply saying: "Moved permanently", which is instructing Google to actually take new URL on account and prioritize it.
If the page doesn't exist, and we actually have no idea why someone could type this link, as this URL never existed and is just wrong, then we serve 404 "Not Found". It simply means that the URL is wrong, and someone (or some other website) has fooled you to follow this link. You shouldn't automatically redirect user from this page, but place a link to the homepage instead, so user can choose his action.
If the page doesn't exist, and we know that we had this page, but it doesn't exist, and it will not exist in the future as well (we has simply decided that we will no longer have this page), then serve 410 "Gone" page, with a link to homepage as well, and let user decide.
HTTP codes, are not just a theory, it's a standard we should use. I noticed, that many 404 pages are served without correct HTTP response code, which only suggests that there is a poor development behind it.
More about HTTP response codes here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
From my understanding, a 301 redirect is the best way to retain "link juice" and should be used if the 404 page is referencing has a lot of external links, has substantial traffic, etc.
Sending a generic 404 page straight to the home page is not ideal, as it may confuse the user. Allowing the 404 keeps the page from being repeatedly indexed and crawled by search engines.
Read more about it here: http://moz.com/learn/seo/http-status-codes.
it is not ok to redirect 404 page to another. it's better to correct it and show the old page. if it's impossible you should show 404 page and put some helpful links in it.
if you want to redirect to the correct one it's ok but the best way is to show display original page regardless of duplication. but you must use rel canonical to tell search engines where is the correct version on the page.
https://support.google.com/webmasters/answer/139394?hl=en

301 Redirect in .htaccess for re-submitting URL-s

I want to ask how do I redirect Search Engines to take a second look on my new, fresh, rewritten URL-s?
So, my former URL-s were structured like this :
http://www.sample.com/tutorials.php?name=something
and now they look much more cleaner and better :
http://www.sample.com/tutorials/programming/something.php
So, as I said, I want Google (and other engines) to take a look at my new links, which are much more SEO friendly and for that I will be indexed better.
I was told the 301 redirect method was the best, but I don't have a clue what is it, how it works and where to learn how to use it. So, I am asking you.
Side note : Would updating my sitemap.xml file and re-submitting it to Google Webmaster Tools help in this process?
Thanks in advance!
There are 2 kinds (in this context) redirects. When a client, be it a browser, search engine indexing bot, or whatever, requests a URI, the server can tell the client "What you are looking for exists, but it's somewhere else". In the case of a 302 or temporary redirect, it's essentially telling the client "What you are looking for exists, but it's temporarily over here at this URL". In the case of a 301 or permanent redirect, it's essentially telling the client "What you are looking for exists, but it has permanently moved over to this URL".
In the case of the later, browsers, proxy servers, and search engine indexes know that the old URL is no longer valid and to stop using it, and from now on to use the new URL that was returned by the server via a 301 redirect. In the case of a search engine like Google, it has an index of the old URL and all the data that its accumulated over the lifetime of that URL assoicated with it. When one of its bots sees a 301, it knows that the old URL, and its content, isn't gone, but it just permanently moved to another URL. All of the associated data Google has collected for the old URL gets trasnfered to the new URL. Google can probably figure most of this stuff out without a 301 redirect, but it's a sure way to make sure Google has got a right.
You can do such a redirect via mod_rewrite:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /tutorials\.php\?name=([^&\ ]+)
RewriteRule ^ /tutorials/programming/%1.php [L,R=301]
You should put this near the top of the htaccess file in your document root. The condition checks that an actual request has been made for /tutorials.php with a query string name="something". The "something" part gets grouped by the match and is accessed via the %1 backreference.
The 301 redirect is a response that the server can make which signals to the user (or search engine) that the page they are looking for has been permanently moved to a specified other page. It is possible to configure apache to give a 301 for certain urls, but it is probably easier to have the whatever server-side language you are using take the request, and then issue a 301.
The chances are that Google will work out what is going on fairly quickly without 301s or anything else, but submitting a sitemap to them or using the URL Parameters functionality in Google's Webmaster Tools might help.

Force entry url

For SEO purposes. How do I force user gets redirected to mysite.com/index when types mysite.com on browser ?
I've tried Redirect / en/index
But I'm getting "Firefox has detected that the server is redirecting the request to this address in a way that will never end."
Also, can this redirection consired set language (php psession, cookies?)
p.s. xampp/windows
Redirect works on path prefixes. Redirect / … matches any path its prefix is / (so virtually any path). Use RedirectMatch instead:
RedirectMatch ^/$ /en/index
I believe the error you're getting from Firefox is because you're entering an infinite loop with this redirection. If you try to redirect to a page that doesn't exist, and your server is set up to redirect to a page that doesn't exist on 404, you'll enter a loop. So, ensure that your redirect is going somewhere significant. Does /index exist? Try redirecting to Google instead and see if you get the same error.
(My server knowledge is limited to goofing around while working on school projects, so take anything I say with a grain of salt)
This probably means you have an error in your redirect code. What Firefox is detecting is that the page are trying to view is redirecting you to itself. Without this protection it would just seem like the page wasn't loading.
If you are running windows on your workstation, I would recommend downloading Fiddler2. It will let you see the series of redirects that your server is sending.