What does the Torah mean when it gives the reason for not taking Yisrael via the land of the P'lishtim (the shortest route) as "because it was near"?
Rashi Rashbam and Ramban #1 (citing the Ibn Ezra): Hashem was afraid that, since it was easy to return to Egypt the way they had come, at the slightest excuse, they would make their way back. 1
Ramban #2: This is not the reason why Hashem did not take them via the P'lishtim, but why He ought to have done so. 2
Which war is the Pasuk referring to?
Rashi (citing the Mechilta) and Ramban #2: The Pasuk is referring to any future war that they might be forced to enter into, such as that of the Amoleki and the Cana'ani, as recorded in Shelach (Bamidbar 14:45).
Ramban #1: It is referring to the battle with the P'lishtim, which they would have had to enter into had they traveled along that route. 1
Rashbam: It is referring to the battles pertaining to the conquest of Cana'an.
Seforno: Since the route via P'lishtim was close to Egypt and was used by many travelers, Pharaoh was bound to receive a report about Yisrael's whereabouts. As a result, Pharaoh would gather an army to attack Yisrael, who would take fright and return to Egypt. 2 So Hashem took them on a roundabout route via uninhabited terrain. 3
Targum Yonasan: This refers to the two hundred thousand 4 men of Efrayim, who left Egypt early and went to Cana'an by way of the P'lishtim, were they began to plunder the herds of cattle belonging to the men of Gas, who retaliated by wiping them out. 5 Hashem knew that, if Yisrael would travel the same route and come across the remains of the B'nei Efrayim, they would take fright and return to Egypt.
Now that they traveled via the desert, they were not destined to encounter any wars until they reached the land of Sichon and Og. As for the battle with Amalek (later in the Parshah), that was no reason to return to Egypt, seeing as it was not they (Yisrael) who arrived at their land, but Amalek who attacked them, and they had no option but to fight in self-defense. Moreover, they were already too far away from Egypt to make their way back on their own (Ramban).
Just as some of them wanted to do at the Yam-Suf (See Targum Yonasan 14:13). Targum Yonasan adds that they were the dry bones that Yechezkel would bring back to life in the time of Nevuchadnetzar (See Na'ar Yonasan).
Indeed, when Pharaoh suddenly caught up with them at the Yam-Suf (See later, Shemos 14:10) they wanted to return, but were unable to, since Pharaoh would not have accepted them (Seforno, Pasuk 18).
This was a Divine punishment for leaving Egypt thirty years before the allotted time (Targum Yonasan).
How could Heshem even contemplate taking Yisrael via the land of P'lishtim, bearing in mind that He intended to first take them to Har Sinai to receive the Torah, as He told Moshe by the Burning Bush (See Shemos, 3:12)?
Seforno: Although the quickest way to Har Sinai was via P'lishtim, Hashem deliberately took Yisrael on a longer route via the Yam-Suf, in order to drown the Egyptians there.