In 1994, when I was 25 years old, I spent several weeks traveling alone in Morocco. Previously, I had lived (alone) in Egypt for a year and had traveled alone to Syria and Jordan. I didn't find the level of harassment in Morocco to be higher than in those countries, but I realized that by then I had internalized several rules that helped make my trip more pleasant. Upon my return from Morocco I wrote this document that may still be of use to women, and even men, traveling alone there.
1. Don't talk to people who approach you
Most "nice" people don't approach strangers in the street. While it's quite natural to talk to your fellow passengers in a bus or train, or with the merchants or fellow customers, when you go shopping, people who approach you in the street out of the blue, are, more often than not, hustlers. In the case of women I would say that that will always be the case. Moroccan men would never approach a Moroccan woman they respected, if they approach you they are just showing their lack of respect (I actually tested this my last day in Morocco. A man kept asking me if I needed help, as I strolled through the market place in Tangier. I decided to confront him and ask him what made him think I would need any help, and I stated that he would never approach a Moroccan woman that way. He, of course, protested that that was not true. Fortunately for me, two Moroccan women were coming towards us at that point. I demanded that he offer his help to them. He, of course, refused, and explained that he respected them more than he respected me and thus would not approach them).
The best thing to do is ignore them. Pretend they are not there, even when they insist that you are being rude, claim that they are human, or complain that you are in their country. If they were good people they wouldn't bother you. When they got too irksome, I used to tell them, in classical Arabic, as I don't know much Moroccan Arabic,
"I do not speak with men of the street" La atakallem ma'a rrijalati shshari
I would say that loud enough so that people around us would hear me, and realize that I was behaving properly (Moroccan women are unlikely to speak with men they meet in the street). It generally worked. Often they would say "oh, you are like Moroccan woman", and even when they insisted, it would not be for long. Do not, though, offer more explanations than this. Once a conversation is initiated, they will not allow it to stop, even if they have to follow you everywhere.
2. Walk fast
That way you can avoid hearing most of the things people say to you, and what you don't know won't bother you. Many Moroccan men are under the impression that you do want their attention, the more things you do to show them that you will not speak with them, the more likely they'll get tired and try somebody else.
3. Do not brush up on your French or Moroccan Arabic
Ok, Ok, both are extremely useful for getting along in the country, but insults, come-ons, etc. are much less effective when you cannot understand them. For all I know, half the men in the bazaar where asking me to f... them, but as they said so in French or Moroccan Arabic I could pretend they were not even speaking to me. After all, I have no idea what they said.
4. When you walk, try to follow women or couples closely
Moroccan men are extreme cowards. If you are close to a woman (especially a middle age one) or a couple, they are less likely to say anything to you, as the woman in question could assume it was directed to her and confront them. So it pays to walk with them.
5. Don't be afraid to confront them
As I said, they are cowards. Often times, I've had men follow me around the markets and the city, even waiting me out, when I stopped at a store. Still, when I decided to confront them, they usually ran away. There is no point threatening them with the police, they are not afraid, they probably paid them off. But confronting them may startle them enough to make them decide to go elsewhere.
6. Don't believe anything they say
Hustlers are great liars too. They will try to direct you the wrong way (ask an uninterested party), convince you that the medina is dangerous or complicated (certainly not much more than your average airport), and of course, they will always claim that they are not commission guides (they always seem to have their own shop). Even merchants will never admit that the man who took you to their store is a commission guide, but chances are that if someone took you, or followed you to a shop, he will get a commission on what you buy (and you will pay more than you should).
7. If you need help, ask women or older gentlemen
Most hustlers are young and male.
8. Don't feel guilty
Yes, Morocco is a poor country, but you don't need to feel it's up to you to enrich every person who comes across your path. I personally decided on an amount I would donate a day, and generally gave money to older men and women who were unable to work.
9. Dress conservatively
You heard it a million times, but it works. Dressing conservatively does not mean dressing like your grandmother, basically it means to avoid tank-tops (or very tight tops), shorts and mini-skirts. I found that people treated me the same whether I wore long skirts or pants, so you shouldn't feel like you "have to wear a skirt." As you can't go to mosques in Morocco, it really doesn't make a difference (a warning, though, if you travel to (almost) any country where you can enter mosques, be advised that you must wear a skirt and a long-sleeve top). Wearing sunglasses also helps, as it makes it so much more difficult for hustlers to make eye-contact with you (and easier for you to pretend not to see them).
If you want to dress as a Moroccan woman you have two choices. One, you can go for the "traditional" look and sport a djellaba. This is a good idea, especially if you are traveling alone, and you are not super fair (many Berbers are quite fair, and have blue eyes, so even if you are not dark-skin you can "pass"). You can buy a djellaba in the souks (remember to bargain) and just wear it over your normal clothes. You don't need to wear a scarf, tying long hair into a braid or ponytail is common enough. For a more "authentic" effect, you may want to wear shoes or sandals instead of sneakers. The whole point of wearing a djellaba is not to make people think that you are Moroccan, but to blend in enough so that hustlers don't come after you. I tried several times, and it gave a great sense of freedom to be able to walk through the medina without having people give me a second look or thought.
If you don't feel comfortable in a djellaba, you may try wearing tights or tight pants and leather jackets (or big tops, if it's too hot for leather). That's the current most common look of "westernized" Moroccan women, and if you look like that, chances are people will think you are Moroccan.
10. Tie your hair
This bears repeating. Wearing your hair in a sole braid or ponytail (or under a hat or scarf) will decrease sexual harassment considerably. I am not sure why, I guess Moroccan men find hair very sexy, but every time I wore my hair loose, I had many more men coming on to me.
My general attitude is to not trust anybody, or rather, any man. Women in general (with the exception of the Berber women who try to sell you "silver" jewelry in Marrakesh) are wonderful, though you generally have to approach them, rather than wait for them to approach you. Of course, most people are not "out to get you", but it pays to be careful. If someone invites you over for dinner and you feel comfortable enough to go, make sure to note the way and bring a present (it's the polite thing to do, plus it saves you, just in case the meal was a ruse to sell you something, from being "guilted out" into buying something -it happens).
Trust, as anywhere else, can be built over time. I met many Moroccan men with whom I had wonderful conversations and began to develop friendships. And by far most of the Moroccans I met, were very nice and friendly, and more generous than most other people I know. When I was Fez, I ran out of Moroccan money and all the banks in the medina (where I was staying) were closed. I asked the owner of the hotel where I was staying to let me pay the bill the next day, when I would hopefully be able to change. Not only did she allow me to pay the bill the next day, but after hearing my plight, she lent me 100dh so I could have enough money for food! I don't think that the people at the local Holiday Inn would be so inclined.
Have a great time!