# Mathematica can't replace integer multiple of 2 in power

I have some terms contain

ww=a+a^2+a^6+a^-4


where

(a^2)^p_. ->  -dx[p] Exp[-x[p]] x^2


but Mathematica only replace power 2 of a. how can I fix this problem

1/a^4 + a + a^6 - E^-x[1] x^2 dx[1]


The issue is the form of the exponents after expansion: ww looks like Plus[Power[a, -4], a, Power[a, 2], Power[a, 6]] (see FullForm in the documentation).
When you use a replacement of (a^2)^p_, it looks to replace terms which appear as Power[Power[a, 2], p_]. These aren't the same thing to the symbolic parser, even if mathematically they can often be intended to mean the same thing.
ww /. (a^p_ /; Divisible[p, 2] :> -dx[p/2] Exp[-x[p/2]] x^2)

This can be read roughly as: ww but replace a^p_ where p is divisible by 2 with the expression (but substituting in p/2 where appropriate).