Workplace bans on the wearing of "any political, philosophical or religious sign" such as headscarves need not constitute direct discrimination, Europe's top court has ruled.
But the ban must be based on internal company rules requiring all employees to "dress neutrally", said the European Court of Justice (ECJ).
It cannot be based on the wishes of a customer, it added.
This is the court's first ruling on the wearing of headscarves at work.
The ECJ's ruling was prompted by the case of a receptionist fired for wearing a headscarf to work at the security company G4S in Belgium.
The issues of Muslim dress and the integration of immigrant communities has featured prominently in debates in several European countries in recent years.
Austria and the German state of Bavaria have recently announced bans on full-face veils in public spaces.
Rights group Amnesty International said Tuesday's ECJ rulings were "disappointing" and "opened a backdoor to... prejudice".
The ECJ ruled on the case of Samira Achbita, fired in June 2006 when, after three years of employment, she began wearing a headscarf to work.
She claimed she was being directly discriminated against on the grounds of her religion and Belgium's court of cassation referred the case to the EU's top court for clarification.
At the time of Ms Achbita's hiring an "unwritten rule" had been in operation banning overt religious symbols, and the company subsequently went on to include this explicitly in its workplace regulations, the court explained in a press release about the ruling.
That covered "any manifestation of such beliefs without distinction", and was therefore not discriminatory, it said.
Crucifixes and skullcaps
It said "an employer's desire to project an image of neutrality towards both its public and private sector customers is legitimate" - but national courts had to make sure this policy of neutrality had been applied equally to all employees.
In practice, such a policy must therefore also ban other religious insignia such as crucifixes, skullcaps and turbans, the court confirmed to the BBC.
To avoid claims of indirect discrimination, national courts must ascertain that people adhering to a particular religion or belief have not been put at a particular disadvantage, unless "objectively justified by a legitimate aim" achieved by means that are "appropriate and necessary".
For instance, the Belgian court ruling on Ms Achbita's case would need to ascertain whether it could have been possible to offer her another post not involving visual contact with customers.
The ECJ also considered the case of design engineer Asma Bougnaoui, who lost her job at French firm Micropole, after a customer complained that she wore an Islamic headscarf.The court ruled that any ban on headscarf could not be based on "subjective considerations".
"The willingness of an employer to take account of the wishes of a customer no longer to have the services of that employer provided by a worker wearing an Islamic headscarf cannot be considered a genuine and determining occupational requirement," it said.
A French court would have to determine whether the company in this case had dismissed Ms Bougnaoui solely to satisfy a customer or in accordance with a wider internal prohibition on religious symbols, the court ruled.
'Pandering to prejudice'
For years, courts across Europe have faced complex decisions on religious symbols in the workplace.
Jonathan Chamberlain, a partner at UK firm Gowling WLG, told the BBC that Tuesday's ruling reflected "what has been the UK's approach for some years".
Germany's constitutional court ruled in 2015 a ban on teachers wearing the headscarf across the country's 16 states was unconstitutional. Such as measure was only justified if religious symbols represented a "concrete danger, or the disturbance of school peace".
But John Dalhuisen, director of Amnesty International's Europe and Central Asia programme, said the ECJ's decision gave "greater leeway to employers to discriminate against women - and men - on the grounds of religious belief".
"The court did say that employers are not at liberty to pander to the prejudices of their clients. But by ruling that company policies can prohibit religious symbols on the grounds of neutrality, they have opened a backdoor to precisely such prejudice."
The British Humanist Association, meanwhile, found more nuance in the ruling, saying that while direct discrimination had been ruled out, whether the company policies constituted indirect discrimination or not "has been remitted back to the Belgian and French courts to determine".