Age discrimination may be illegal, but it’s also a sad fact of life. In a 2013 AARP survey, 64 percent of 45- to 74-year olds said they had seen or experienced it in the workplace.

Other surveys have found that older employees who lose their jobs take longer than younger workers to find a new one. Bureau of Labor Statistics figures released in February, for example, showed that men and women between 55 and 64 were unemployed for an average of 44 weeks, compared to 32 weeks for people age 35 to 44.

Cautionary tales like those have put many of us who are over 50 in defense mode. We wonder what we can do to save our jobs, or if that isn’t possible, get another one more quickly.

Related: Quiz: Test Your Retirement Savings Savvy

First, some good news: There’s evidence that the situation may be improving. A CareerBuilder survey released in February found that 54 percent of private sector employers had hired 50-plus workers in 2014, up from 48 percent in 2013. What’s more, 57 percent planned to do so in 2015.

Nella Barkley, whose Crystal-Barkley Corporation advises both individuals and organizations on career planning issues, says she has noticed a similar trend lately. Some companies that thinned their ranks of older, more experienced workers during the recession have suffered bottom-line consequences and now view it as a failed experiment. As a result, she adds, “a little gray hair is valued more now than it was five years ago.”

Of course, if you’re in the 50-plus bracket or will be arriving there anytime soon, that’s no reason to let your guard down. Here are a few steps you can take to protect yourself, based on advice from Barkley and other experts.

1. Enjoy your work, and let it show. That’s true at any age, Barkley says, but especially for more mature workers who are too easily stereotyped as grumpy old men (or women).

2. Stay focused. Try not to let fear of losing your job distract you from actually doing it. A 2014 survey of HR professionals by the Society for Human Resource Management found that compared to other workers, older employees were valued for being more mature, more reliable, and having a stronger work ethic. Don’t give them any reason to suspect otherwise.

3. Come up with fresh ideas. Don’t leave that to your younger colleagues, Barkley says. You want to be perceived as someone who is forward thinking and not just following along. But make sure you’re also seen as an employee who plays well with others, especially younger others.

4. Keep up appearances. Stay physically fit and invest in a good wardrobe, Barkley suggests. Don’t try to dress younger, but do dress well and appropriately for the environment you work in.

Related: Related: 10 Reasons Adults Need Vaccinations

5. Know the warning signs. Even if you’re totally invested in your job and things seem to be going smoothly, it pays to stay alert. Consider it a bad omen if you’re suddenly left out of key meetings or not consulted on important initiatives that you would have been in the past, Barkley says. 

6. Have an exit strategy just in case. You may have more options than you realize, but the time to think about them is before you find yourself in a crisis situation. If you believe your job is in jeopardy but would like to stay with your current employer, consider making a proposal that would meet both its needs and yours. For example, could you switch to another department or become a consultant or contract worker?

Related: How to Create a Rainy-Day Fund

If staying put is impossible or just doesn’t appeal to you, you might find other opportunities within your current field, especially if you’ve kept current with new developments, stayed visible and maintained cordial relationships with your competitors, Barkley says.

If you haven’t done it all along, now’s a good time to start making friends outside your organization. The Society for Human Resource Management survey reported that employee referrals were the primary way companies recruit older workers.

You might also consider switching careers or taking an entrepreneurial turn and becoming your own boss. Older people can be very successful as entrepreneurs if they research the market thoroughly and have the right skills, Barkley says.

7. Know your rights. If you’re over 40, you have rights under the Age Discrimination in Employment Act. Even if you don’t intend to pursue an age- discrimination claim — because of the legal costs, hassle, or not wanting to burn bridges — they’re worth knowing. You can learn more at the U.S. Equal Opportunity Commission website.

Greg Daugherty is a longtime personal-finance writer and a former senior editor of Money magazine.