apache keeps old .htaccess settings (in rewriterule) - apache

I am testing some basic .htaccess rewriterules and I am pretty sure that even after deleting a rule in .htaccess and saving the document, apache ignores it and acts like the rule was still there (only for earlier requested sites) - even after apache restart. It is driving me crazy, the behavior is really mad. Is there any apache cache which is about to be cleaned or the problem is elsewhere?

It's madness! Not really, it's just annoying.
When you set a redirect in Apache what you're doing is actually configuring headers that are passed to your browser. Your browser keeps a cache of 301 and 302 redirect headers (and other things like DNS) in the event you go back to those pages, so it can save you time. 301 redirects are supposed to be permanent (that's what you're indicating), so if there is no need for the browser to do something like perform a DNS lookup or visit a page based on a redirect, then it will cut corners and use the cache in order to provide you with a faster browsing experience.
You need to flush your browser's cache to prevent the store redirects from happening.
Additionally, you'll want to resubmit your page to Google (in the event it's on the web) in case they've crawled your site while the invalid headers existed.

Related

Apache Rewrite Condition After Upgrade

We recently upgraded a system and have noticed that our URLs have changed. I would like to configure our Apache web server so that it permanently detects the old URL and redirects users to the new URL.
All URL parameters have remained unchanged apart from one, see below;
Old URLs;
https://example.com/products/cat_one/record/1656782?lang=eng&type=grey
https://example.com/products/cat_one/record/1188746?lang=eng&type=blue
https://example.com/products/cat_one/record/4499814?lang=eng&type=black
New URLs;
https://example.com/products/cat/record/1656782?lang=eng&type=grey
https://example.com/products/cat/record/1188746?lang=eng&type=blue
https://example.com/products/cat/record/4499814?lang=eng&type=black
As you can see, the cat_one parameter has changed to cat.
We've been told by the supplier that this kind of redirect isn't possible and it's our responsibility to update all old URLs manually, surely this isn't correct?
How can I achieve this, wither via htaccess, vhosts file, or similar - I've seen various ways to achieve this. I think I require a 301 redirect / rewrite rule?

301 Redirect Still Happening even though its been removed

I am having trouble with some old 301 redirects.
They have been removed from the htaccess but still seem to be working.
Some of the redirects have been removed for over 1 year but they still redirect as if they are present.
Ive tried different browsers/private browsing, restarting apache, flusing caches on the cms system and no luck.
The 301s were set out like this
Redirect 301 /example.com http://www.example.com/new-url
Our CMS is magento
Check if you have same redirects in Magento catalog rewrites (just a guess). Post your complete htaccess and give a real example of redirect. It can also be caused by custom varnish vcl (but very rare)
I fixed my issue by looking for other htaccess files in the ftp and found that an old htaccess had made its way into the root of the ftp which was conflicting with the correct one.
This was acting as a back up htaccess to the correct one and redirecting old URLS still.

Is there an Apache/Plesk server setting that governs https:// behavior?

Context:
I've recently moved a site to a new host, and moved the SSL certificate from the old host to the new one. The code, written in PHP, is a big mess made by someone no longer available many years ago. Because of this, I'm hoping to figure out something related to the configuration of the server that can fix the issue so I don't have to reverse-engineer the rather messy code.
Problem:
When users navigate to an area of the site that uses https://, all goes according to plan. The problem, however, arises when they click a link in the navigation that is normally to an http:// part of the site. On hover, you can see that the target URL incorrectly includes "https://". When the user tries to go to a non-secure area with https:// in front, either by clicking one of those altered links or by typing it into the location bar of the browser, they are redirected to the directory without any domain. For example, if you try to go to "https://domain.org/site/", the browser is redirected to only "/site", which of course cannot be found.
Theoretical solutions:
Is there a setting in Plesk which governs the "stickiness" of https? One way to fix the problem is to stop the non-secure links from acquiring https://.
Is there an obvious reason why whatever script or file the site is using to redirect would break when an un-secure area is accessed via https://? Is there a server setting that would have made this function differently on the new server via the old server?
I don't have access to see what exactly the configuration of the old server was. Is it likely that this could be caused by a difference in PHP version? If so, any suspicions about what the problem would be?
Is there some workaround with .htaccess that can manually redirect all but certain secure areas of the site to http:// when they are accessed via https://, presumably before the site's redirect script is activated?
Thank you for any help!!
Yes, since Plesk 17 (Onyx):
For older versions you can create .htaccess files which will rewrite request from https pages to http, based on referrer:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https://domain.org [NC]
RewriteRule ^(.*)$ http://domain.org/$1 [L,R=301]

Apache throwing 403 on www.example.com/dir/.php

I've discovered from Google Webmaster Tools that Google has found a bad link somewhere that is throwing a 403 error on my server.
The url is like this:
http://www.example.com/directory/.php
I don't know how that url has come about and the site is too complicated for me to find out, but I'd like to simply place a 301 redirect to:
http://www.example.com/directory/
I've put the correct rule in .htaccess for the redirect, but it doesn't appear to be triggered. It's almost as if the 403 is being generated before .htaccess is processed. Does anyone know why this might be and how I can successfully get the user redirected to the new page?
Except for the fact that the rule may be indeed incorrect, this could also be because this involves looking for a file with a filename starting with a ..
These files are usually "hidden" from the outside world, so it might be that either your Apache (configuration) or your OS does not allow serving this file.
Without knowing more about the configuration, this cannot be analyzed though. You could test it by creating a file called ".test" and see if that's reachable.

mod_rewrite - Does Apache caches .htaccess rules? (still follow rules even after deleting the .htaccess file)

I was doing some tests with mod_rewrite in my wamp environment.
I tested a simple rule that I put at the root of one of my websites and asked it to redirect any request ending with index.php to localhost (there is no sense to it, just wanted to check the rule)
It worked, but after, any change I'd made to my .htaccess file rule was not reflected.
After a while I just decided to delete the .htaccess... well it's still doing redirection! I just don't understand it. Does Apache cache the rules or something (restarting services trough wamp menu didn't change anything)
(Don't ask for the exact rule I used, since I deleted the file, I don't think it's relevant anyway)
.htaccess files are processed each time a request comes through. It is possible that your browser cached the request being forwarded. Did you try it with httpfox or anything to see what the headers said?
Have you tried deleting the browser cache?